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

@ -58,9 +58,10 @@ typedef struct {
} ByteWriterContext;
static void bw_expand(ByteWriterContext *bwc){
bwc->Data = realloc(bwc->Data, (bwc->Size <<= 1));
if(!bwc->Data)
void * ptr;
if(bwc->Size > SIZE_MAX/2 || !(ptr = realloc(bwc->Data, bwc->Size<<=1)))
Shutdown_M("%sCould not allocate memory for %s section.\n", "hitasm: Error: ", bwc->Name);
bwc->Data = ptr;
}
static void bw_write32(ByteWriterContext *bwc, uint32_t value){