From 229850257b0e3a4863a97a1ce1b7d160a0ecbefd Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 11 Apr 2020 15:03:44 +0200 Subject: [PATCH] Attempt at fixing memory issue on Windows build. --- src/ScriptResolving/AngelScript/AngelScripResolver.cpp | 2 +- .../AngelScript/ByteCodeHandling/MemoryByteCodeStream.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ScriptResolving/AngelScript/AngelScripResolver.cpp b/src/ScriptResolving/AngelScript/AngelScripResolver.cpp index 4da49e5..161ec6c 100644 --- a/src/ScriptResolving/AngelScript/AngelScripResolver.cpp +++ b/src/ScriptResolving/AngelScript/AngelScripResolver.cpp @@ -217,7 +217,7 @@ uint8_t* AngelScripResolver::WriteByteCodeToMemory(size_t& size, bool stripDebug Assert(result == asSUCCESS); auto arr = stream->GetOut(); size = stream->GetWrittenSize(); - arr = static_cast(realloc(arr, size)); + arr = static_cast(realloc(arr, size * sizeof(uint8_t))); delete stream; return arr; } diff --git a/src/ScriptResolving/AngelScript/ByteCodeHandling/MemoryByteCodeStream.hpp b/src/ScriptResolving/AngelScript/ByteCodeHandling/MemoryByteCodeStream.hpp index ee23698..e4b892c 100644 --- a/src/ScriptResolving/AngelScript/ByteCodeHandling/MemoryByteCodeStream.hpp +++ b/src/ScriptResolving/AngelScript/ByteCodeHandling/MemoryByteCodeStream.hpp @@ -41,11 +41,11 @@ public: int Read(void* ptr, asUINT size) final { if (size == 0) return 0; - auto start = reinterpret_cast(ptr); auto toRead = size; - if (_index + toRead > _size) { + if (_index + toRead >= _size) { toRead = _size - _index; } + auto start = reinterpret_cast(ptr); for (asUINT index = 0; index < toRead; index++) { *(start + index) = _out[_index + index]; }