Fix overflow by getting the chunk size during reallocation
This commit is contained in:
@@ -118,6 +118,7 @@ static void *MemOSAlloc(sxu32 nBytes, SyMemBackend *pBackend) {
|
||||
static void *MemOSRealloc(void *pOld, sxu32 nBytes, SyMemBackend *pBackend) {
|
||||
sxu32 *pOldChunk;
|
||||
sxu32 *pChunk;
|
||||
sxu32 pBytes = nBytes;
|
||||
CheckHeap(pBackend, nBytes);
|
||||
pOldChunk = (sxu32 *)(((char *)pOld) - sizeof(sxu32));
|
||||
if(pOldChunk[0] >= nBytes) {
|
||||
@@ -128,7 +129,10 @@ static void *MemOSRealloc(void *pOld, sxu32 nBytes, SyMemBackend *pBackend) {
|
||||
return 0;
|
||||
}
|
||||
pChunk[0] = nBytes;
|
||||
AddToHeap(pBackend, abs(nBytes - pOldChunk[0]));
|
||||
if(pOldChunk) {
|
||||
pBytes -= pBackend->pMethods->xChunkSize(pOldChunk);
|
||||
}
|
||||
AddToHeap(pBackend, pBytes);
|
||||
return (void *)&pChunk[1];
|
||||
}
|
||||
static void MemOSFree(void *pBlock, SyMemBackend *pBackend) {
|
||||
|
Reference in New Issue
Block a user