From 7d5a81d375a9b5d8d409a11a3936fa9391f83082 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Wed, 8 Sep 2021 18:17:19 +0200 Subject: [PATCH] Prevent GCC from turning PRAM_Zalloc into PRAM_Malloc + memset --- cgdoom/cgdoom-alloc.c | 4 ++-- cgdoom/w_wad.c | 18 +++++++++++++----- cgdoom/z_zone.c | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cgdoom/cgdoom-alloc.c b/cgdoom/cgdoom-alloc.c index e989309..7b0c938 100644 --- a/cgdoom/cgdoom-alloc.c +++ b/cgdoom/cgdoom-alloc.c @@ -91,8 +91,8 @@ void CGD_PRAM_Free(void *ptr) void *CGD_PRAM_Zalloc(size_t size) { - uint32_t *ptr = CGD_PRAM_Malloc(size); + uint32_t volatile *ptr = CGD_PRAM_Malloc(size); if(!ptr) return NULL; for(int i = 0; i < size / 4; i++) ptr[i] = 0; - return ptr; + return (void *)ptr; } diff --git a/cgdoom/w_wad.c b/cgdoom/w_wad.c index 83b0444..9945c26 100644 --- a/cgdoom/w_wad.c +++ b/cgdoom/w_wad.c @@ -60,9 +60,9 @@ // Location of each lump on disk. lumpinfo_t* lumpinfo; -static int numlumps; +static int numlumps = 0; -void** lumpcache; +void** lumpcache = NULL; // @@ -157,12 +157,15 @@ static int W_AddFile () // int W_InitMultipleFiles(void) { + int previous_numlumps = numlumps; + // open all the files, load headers, and count lumps numlumps = 0; + /* CGDoom: Loading multiples files hasn't been tested for a long time and may + not work due to the allocation of lumpcache */ + // will be realloced as lumps are added - //lumpinfo = (lumpinfo_t*)CGDMalloc(1); - //CGD: CGDrealloc accepts NULL lumpinfo = NULL; if(!W_AddFile ()) { @@ -176,7 +179,12 @@ int W_InitMultipleFiles(void) // set up caching //printf ("numlumps = %i \n",numlumps); - lumpcache = (void **)CGD_PRAM_Zalloc(numlumps * sizeof(*lumpcache)); + if (lumpcache != NULL && numlumps <= previous_numlumps) { + /* Don't realloc when not needed */ + } + else { + lumpcache = (void **)CGD_PRAM_Zalloc(numlumps * sizeof(*lumpcache)); + } if (!lumpcache) { diff --git a/cgdoom/z_zone.c b/cgdoom/z_zone.c index 2746488..2f34815 100644 --- a/cgdoom/z_zone.c +++ b/cgdoom/z_zone.c @@ -470,7 +470,7 @@ void Z_ChangeTag2(const void* ptr,int tag ) if (block->id != ZONEID) { - I_Error ("Z_ChangeTag: freed a pointer without ZONEID"); + I_ErrorI ("Z_ChangeTag: freed a pointer without ZONEID", (int)ptr, 0, 0, 0); } if (tag >= PU_PURGELEVEL && (unsigned)block->user < 0x100)