diff --git a/source/duke3d/src/gameexec.cpp b/source/duke3d/src/gameexec.cpp index d451b9e88..e580a1c95 100644 --- a/source/duke3d/src/gameexec.cpp +++ b/source/duke3d/src/gameexec.cpp @@ -4398,6 +4398,7 @@ finish_qsprintf: if (numElements > 0) { size_t const newBytes = Gv_GetArrayAllocSizeForCount(arrayNum, numElements); + size_t const readBytes = min(newBytes, filelength); size_t const oldBytes = Gv_GetArrayAllocSize(arrayNum); intptr_t *& pValues = aGameArrays[arrayNum].pValues; @@ -4419,7 +4420,7 @@ finish_qsprintf: { void * const pArray = Xcalloc(1, newBytes); - kread(kFile, pArray, newBytes); + kread(kFile, pArray, readBytes); if (flags & GAMEARRAY_UNSIGNED) { @@ -4437,7 +4438,8 @@ finish_qsprintf: } #endif default: - kread(kFile, pValues, newBytes); + memset((char *)pValues + readBytes, 0, newBytes - readBytes); + kread(kFile, pValues, readBytes); break; } } diff --git a/source/duke3d/src/gamevars.cpp b/source/duke3d/src/gamevars.cpp index ee9642a58..eba571c1a 100644 --- a/source/duke3d/src/gamevars.cpp +++ b/source/duke3d/src/gamevars.cpp @@ -602,7 +602,7 @@ size_t __fastcall Gv_GetArrayCountFromFile(int const arrayIdx, size_t const file size_t const elementSize = Gv_GetArrayElementSize(arrayIdx); size_t const denominator = min(elementSize, sizeof(uint32_t)); - return filelength / denominator; + return (filelength + denominator - 1) / denominator; } int __fastcall Gv_GetArrayValue(int const id, int index)