diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index 85802b6de..f8056ad51 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -443,12 +443,19 @@ AllocMem(int size) void * ReAllocMem(void *ptr, int size) { + if (ptr == nullptr) + return AllocMem(size); + + if (size == 0) + { + FreeMem(ptr); + return nullptr; + } + uint8_t* bp; MEM_HDRp mhp; uint8_t* check; - ASSERT(size != 0); - ASSERT(ValidPtr(ptr)); mhp = (MEM_HDRp)(((uint8_t*) ptr) - sizeof(MEM_HDR)); @@ -506,11 +513,12 @@ CallocMem(int size, int num) void FreeMem(void *ptr) { + if (ptr == nullptr) + return; + MEM_HDRp mhp; uint8_t* check; - ASSERT(ptr != NULL); - ASSERT(ValidPtr(ptr)); mhp = (MEM_HDRp)(((uint8_t*) ptr) - sizeof(MEM_HDR)); @@ -521,39 +529,6 @@ FreeMem(void *ptr) free(mhp); } -#else -SWBOOL -ValidPtr(void *ptr) -{ - return TRUE; -} - -#if 0 -void * -AllocMem(int size) -{ - return malloc(size); -} - -void * -CallocMem(int size, int num) -{ - return calloc(size, num); -} - -void * -ReAllocMem(void *ptr, int size) -{ - return realloc(ptr, size); -} - -void -FreeMem(void *ptr) -{ - free(ptr); -} -#endif - #endif int PointOnLine(int x, int y, int x1, int y1, int x2, int y2) diff --git a/source/sw/src/game.h b/source/sw/src/game.h index dbcf6a3f3..b6e480834 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -1754,18 +1754,18 @@ typedef struct unsigned int size, checksum; } MEM_HDR,*MEM_HDRp; +#if !DEBUG +# define ValidPtr(ptr) ((SWBOOL)(TRUE)) +# define AllocMem(size) Xmalloc(size) +# define CallocMem(size, num) Xcalloc(size, num) +# define ReAllocMem(ptr, size) Xrealloc(ptr, size) +# define FreeMem(ptr) Xfree(ptr) +#else SWBOOL ValidPtr(void *ptr); -#if 0 void *AllocMem(int size); void *CallocMem(int size, int num); void *ReAllocMem(void *ptr, int size); void FreeMem(void *ptr); -#else -// Make these #defines so that MSVC's allocation tracker gets correct line numbers -#define AllocMem malloc -#define CallocMem calloc -#define ReAllocMem realloc -#define FreeMem free #endif typedef struct