fix track memroy overread on realloc example problem

This commit is contained in:
toddouska 2013-03-18 11:17:34 -07:00
parent b5d3613946
commit 88938390ba
1 changed files with 8 additions and 0 deletions

View File

@ -1011,6 +1011,14 @@ static INLINE int CurrentDir(const char* str)
{
void* ret = TrackMalloc(sz);
if (ptr) {
/* if realloc is bigger, don't overread old ptr */
memoryTrack* mt = (memoryTrack*)((byte*)ptr - sizeof(memoryTrack));
if (mt->u.hint.thisSize < sz)
sz = mt->u.hint.thisSize;
}
if (ret && ptr)
memcpy(ret, ptr, sz);