Corrected the memory exhaustion trap behavior used when calling realloc

Two more steps are currently required to complete hitutils: write hitld, with support for multiple objects and even .a archives, and implement scan_branch_destinations in hitdump. Then we can seamless modify The Sims 1's HIT routines.
This commit is contained in:
Fatbag 2013-01-23 21:13:25 -06:00
parent 0ec39fd968
commit 558726a9f1
3 changed files with 14 additions and 9 deletions

View file

@ -82,9 +82,12 @@ struct RTTIVector {
Shutdown_M("Failed to allocate memory");
}
T& add(){
if((Count+1)*sizeof(T) > SizeAllocated)
if(SizeAllocated > SIZE_MAX/2 || !(Buffer = (T*) realloc(Buffer, SizeAllocated<<=1)))
if((Count+1)*sizeof(T) > SizeAllocated){
void * ptr;
if(SizeAllocated > SIZE_MAX/2 || !(ptr = (T*) realloc(Buffer, SizeAllocated<<=1)))
Shutdown_M("Failed to allocate memory");
Buffer = (T *) ptr;
}
return Buffer[Count++];
}