Slightly change readarrayfromfile so that attempting to read arrays of a size that does not evenly divide into the requested type rounds up instead of down and zero-pads the difference.

This should help hackish persuits such as reading map files through this command.

git-svn-id: https://svn.eduke32.com/eduke32@6394 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2017-07-28 08:27:38 +00:00
parent 201ee80f87
commit 32ed49e5c5
2 changed files with 5 additions and 3 deletions

View file

@ -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;
}
}

View file

@ -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)