From a557eedf7e2cbd09d55dc9c820d30187bfca1439 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Wed, 23 Sep 2015 17:55:31 +0000 Subject: [PATCH] Remove NULL checks before calling free(): they are unnecessary as per the C standard. Other cleanup includes factoring code into DO_FREE_AND_NULL() macros. git-svn-id: https://svn.eduke32.com/eduke32@5352 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/compat.h | 4 +- polymer/eduke32/build/src/build.c | 27 +++++------- polymer/eduke32/build/src/cache1d.c | 9 ++-- polymer/eduke32/build/src/common.c | 3 +- polymer/eduke32/build/src/compat.c | 2 +- polymer/eduke32/build/src/engine.c | 36 ++++++---------- polymer/eduke32/build/src/glbuild.c | 6 +-- polymer/eduke32/build/src/hightile.c | 14 +++--- polymer/eduke32/build/src/kplib.c | 13 +++--- polymer/eduke32/build/src/lunatic.c | 6 +-- polymer/eduke32/build/src/mdsprite.c | 27 ++++++------ polymer/eduke32/build/src/osd.c | 8 ++-- polymer/eduke32/build/src/polymer.c | 43 ++++++++----------- polymer/eduke32/build/src/scriptfile.c | 11 ++--- polymer/eduke32/build/src/texcache.c | 3 +- polymer/eduke32/build/src/util/arttool.cc | 5 +-- polymer/eduke32/build/src/winlayer.c | 19 ++++---- polymer/eduke32/source/animvpx.c | 3 +- polymer/eduke32/source/astub.c | 32 +++++--------- polymer/eduke32/source/common.c | 6 +-- polymer/eduke32/source/game.c | 36 ++++++++-------- polymer/eduke32/source/gamedef.c | 23 +++------- polymer/eduke32/source/grpscan.c | 8 +--- .../eduke32/source/jaudiolib/src/driver_sdl.c | 6 +-- polymer/eduke32/source/jaudiolib/src/flac.c | 3 +- polymer/eduke32/source/jaudiolib/src/xa.c | 3 +- polymer/eduke32/source/jmact/animlib.c | 3 +- polymer/eduke32/source/jmact/file_lib.c | 5 +-- polymer/eduke32/source/jmact/scriplib.c | 16 +++---- polymer/eduke32/source/lunatic/lunatic_game.c | 5 +-- polymer/eduke32/source/m32common.c | 17 ++------ polymer/eduke32/source/m32def.c | 10 ++--- polymer/eduke32/source/m32vars.c | 18 +++----- polymer/eduke32/source/midi.c | 6 +-- polymer/eduke32/source/premap.c | 11 +---- polymer/eduke32/source/savegame.c | 3 +- polymer/eduke32/source/startwin.game.c | 2 +- polymer/eduke32/source/sw/src/common.c | 3 +- polymer/eduke32/source/sw/src/game.c | 4 +- polymer/eduke32/source/sw/src/scrip2.c | 16 +++---- polymer/eduke32/source/sw/src/sounds.c | 6 +-- 41 files changed, 176 insertions(+), 305 deletions(-) diff --git a/polymer/eduke32/build/include/compat.h b/polymer/eduke32/build/include/compat.h index 36ee4ae5c..115c9b980 100644 --- a/polymer/eduke32/build/include/compat.h +++ b/polymer/eduke32/build/include/compat.h @@ -953,11 +953,11 @@ FORCE_INLINE void *xaligned_malloc(const bsize_t alignment, const bsize_t size) #endif #define DO_FREE_AND_NULL(var) do { \ - if (var != NULL) { Bfree(var); var = NULL; } \ + Bfree(var); (var) = NULL; \ } while (0) #define ALIGNED_FREE_AND_NULL(var) do { \ - if (var != NULL) { Baligned_free(var); var = NULL; } \ + Baligned_free(var); (var) = NULL; \ } while (0) #define MAYBE_FCLOSE_AND_NULL(fileptr) do { \ diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index c0a3a1b3e..a52e9852f 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -718,9 +718,9 @@ int32_t app_main(int32_t argc, const char **argv) initprintf("Definitions file \"%s\" loaded.\n",defsfile); for (i=0; i < g_defModulesNum; ++i) - Bfree (g_defModules[i]); - Bfree (g_defModules); - g_defModules = NULL; // be defensive... + Bfree(g_defModules[i]); + DO_FREE_AND_NULL(g_defModules); + g_defModulesNum = 0; if (E_PostInit()) M32_FatalEngineError(); @@ -733,9 +733,9 @@ int32_t app_main(int32_t argc, const char **argv) initprintf("There was an error loading the sprite clipping map (status %d).\n", k); for (i=0; i < g_clipMapFilesNum; ++i) - Bfree (g_clipMapFiles[i]); - Bfree (g_clipMapFiles); - g_clipMapFiles = NULL; + Bfree(g_clipMapFiles[i]); + DO_FREE_AND_NULL(g_clipMapFiles); + g_clipMapFilesNum = 0; #endif taglab_init(); @@ -2626,8 +2626,7 @@ static int32_t backup_drawn_walls(int32_t restore) } } - Bfree(tmpwall); - tmpwall = NULL; + DO_FREE_AND_NULL(tmpwall); ovh.bak_wallsdrawn = 0; } @@ -6379,8 +6378,7 @@ end_point_dragging: } } - if (origframe) - Bfree(origframe); + Bfree(origframe); } else { @@ -6406,11 +6404,7 @@ end_point_dragging: if (!bakframe_fillandfade(&origframe, i, "Use this as second joining sector? (Y/N)")) continue; - if (origframe) - { - Bfree(origframe); - origframe = NULL; - } + DO_FREE_AND_NULL(origframe); } joinsector[1] = i; @@ -7735,8 +7729,7 @@ end_batch_insert_points: printmessage16("Sector deleted."); } - if (origframe) - Bfree(origframe); + Bfree(origframe); #ifdef YAX_ENABLE for (j=0; jnext; - if (tmp->string) - { - Bfree(tmp->string); - tmp->string = NULL; - } + Bfree(tmp->string); Bfree(tmp); num++; } } while (--remaining >= 0); - Bfree(t->items); - t->items = 0; + DO_FREE_AND_NULL(t->items); } // djb3 algorithm diff --git a/polymer/eduke32/build/src/glbuild.c b/polymer/eduke32/build/src/glbuild.c index e4141a6e8..cbd7ed50e 100644 --- a/polymer/eduke32/build/src/glbuild.c +++ b/polymer/eduke32/build/src/glbuild.c @@ -726,8 +726,7 @@ int32_t unloadgldriver(void) if (!hGLDLL) return 0; #endif - Bfree(gldriver); - gldriver = NULL; + DO_FREE_AND_NULL(gldriver); #if !defined RENDERTYPESDL && defined _WIN32 FreeLibrary(hGLDLL); @@ -1115,8 +1114,7 @@ int32_t unloadglulibrary(void) if (!hGLUDLL) return 0; #endif - Bfree(glulibrary); - glulibrary = NULL; + DO_FREE_AND_NULL(glulibrary); #if defined _WIN32 FreeLibrary(hGLUDLL); diff --git a/polymer/eduke32/build/src/hightile.c b/polymer/eduke32/build/src/hightile.c index e60fb4d21..5421490d0 100644 --- a/polymer/eduke32/build/src/hightile.c +++ b/polymer/eduke32/build/src/hightile.c @@ -94,14 +94,11 @@ void hicinit(void) if (hr->skybox) { for (j=5; j>=0; j--) - if (hr->skybox->face[j]) - Bfree(hr->skybox->face[j]); + Bfree(hr->skybox->face[j]); Bfree(hr->skybox); } - if (hr->filename) - Bfree(hr->filename); - + Bfree(hr->filename); Bfree(hr); hr = next; @@ -160,7 +157,7 @@ int32_t hicsetsubsttex(int32_t picnum, int32_t palnum, const char *filen, float else hrn = hr; // store into hicreplc the details for this replacement - if (hrn->filename) Bfree(hrn->filename); + Bfree(hrn->filename); hrn->filename = Xstrdup(filen); hrn->alphacut = min(alphacut,1.0); @@ -265,13 +262,12 @@ int32_t hicclearsubst(int32_t picnum, int32_t palnum) if (!hr) return 0; - if (hr->filename) Bfree(hr->filename); + Bfree(hr->filename); if (hr->skybox) { int32_t i; for (i=5; i>=0; i--) - if (hr->skybox->face[i]) - Bfree(hr->skybox->face[i]); + Bfree(hr->skybox->face[i]); Bfree(hr->skybox); } diff --git a/polymer/eduke32/build/src/kplib.c b/polymer/eduke32/build/src/kplib.c index 13c45d229..4764e482c 100644 --- a/polymer/eduke32/build/src/kplib.c +++ b/polymer/eduke32/build/src/kplib.c @@ -1400,9 +1400,9 @@ static int32_t kpegrend(const char *kfilebuf, int32_t kfilength, kfileptr += leng; break; case 0xda: - if ((xdim <= 0) || (ydim <= 0)) { if (dctbuf) Bfree(dctbuf); return(-1); } + if ((xdim <= 0) || (ydim <= 0)) { Bfree(dctbuf); return(-1); } - lnumcomponents = (int32_t)(*kfileptr++); if (!lnumcomponents) { if (dctbuf) Bfree(dctbuf); return(-1); } + lnumcomponents = (int32_t)(*kfileptr++); if (!lnumcomponents) { Bfree(dctbuf); return(-1); } if (lnumcomponents > 1) kcoltype = 2; for (z=0; zL) { - Bfree(estate->name); - estate->name = NULL; + DO_FREE_AND_NULL(estate->name); return -2; } @@ -131,8 +130,7 @@ void L_DestroyState(L_State *estate) if (!L_IsInitialized(estate)) return; - Bfree(estate->name); - estate->name = NULL; + DO_FREE_AND_NULL(estate->name); lua_close(estate->L); estate->L = NULL; diff --git a/polymer/eduke32/build/src/mdsprite.c b/polymer/eduke32/build/src/mdsprite.c index 9f2a6add7..f745fd205 100644 --- a/polymer/eduke32/build/src/mdsprite.c +++ b/polymer/eduke32/build/src/mdsprite.c @@ -111,8 +111,7 @@ void md_freevbos() { // OSD_Printf("freeing model %d vbo\n",i); bglDeleteBuffersARB(m->head.numsurfs, m->vbos); - Bfree(m->vbos); - m->vbos = NULL; + DO_FREE_AND_NULL(m->vbos); } } @@ -131,7 +130,7 @@ void freeallmodels() if (models) { for (i=0; iskinmap = sk; else skl->next = sk; } - else if (sk->fn) Bfree(sk->fn); + else Bfree(sk->fn); sk->palette = (uint8_t)palnum; sk->flags = (uint8_t)flags; @@ -2505,22 +2503,21 @@ static void md3free(md3model_t *m) } Bfree(m->head.surfs); } - if (m->head.tags) Bfree(m->head.tags); - if (m->head.frames) Bfree(m->head.frames); + Bfree(m->head.tags); + Bfree(m->head.frames); - if (m->texid) Bfree(m->texid); + Bfree(m->texid); - if (m->muladdframes) Bfree(m->muladdframes); + Bfree(m->muladdframes); - if (m->indexes) Bfree(m->indexes); - if (m->vindexes) Bfree(m->vindexes); - if (m->maxdepths) Bfree(m->maxdepths); + Bfree(m->indexes); + Bfree(m->vindexes); + Bfree(m->maxdepths); if (m->vbos) { bglDeleteBuffersARB(m->head.numsurfs, m->vbos); - Bfree(m->vbos); - m->vbos = NULL; + DO_FREE_AND_NULL(m->vbos); } Bfree(m); diff --git a/polymer/eduke32/build/src/osd.c b/polymer/eduke32/build/src/osd.c index 0fc8100a9..ab36640f9 100644 --- a/polymer/eduke32/build/src/osd.c +++ b/polymer/eduke32/build/src/osd.c @@ -214,7 +214,7 @@ int32_t OSD_Exec(const char *szScript) if (!err || err == 3) // no error message for blank file OSD_Printf("Error executing \"%s\"!\n", szScript); if (i != -1) kclose(i); - if (buf != NULL) Bfree(buf); + Bfree(buf); return 1; } @@ -1981,9 +1981,9 @@ static symbol_t *addnewsymbol(const char *name) } } hash_add(&h_osd, name, osd->numsymbols, 1); - name = Bstrtolower(Xstrdup(name)); - hash_add(&h_osd, name, osd->numsymbols, 1); - Bfree((void *)name); + char * const newname = Bstrtolower(Xstrdup(name)); + hash_add(&h_osd, newname, osd->numsymbols, 1); + Bfree(newname); osd->symbptrs[osd->numsymbols++] = newsymb; return newsymb; } diff --git a/polymer/eduke32/build/src/polymer.c b/polymer/eduke32/build/src/polymer.c index aaf448c76..27b4a9b9f 100644 --- a/polymer/eduke32/build/src/polymer.c +++ b/polymer/eduke32/build/src/polymer.c @@ -884,8 +884,7 @@ void polymer_uninit(void) while (j < MAXPALOOKUPS) { // if (prhighpalookups[i][j].data) { -// Bfree(prhighpalookups[i][j].data); -// prhighpalookups[i][j].data = NULL; +// DO_FREE_AND_NULL(prhighpalookups[i][j].data); // } if (prhighpalookups[i][j].map) { bglDeleteTextures(1, &prhighpalookups[i][j].map); @@ -1271,10 +1270,8 @@ void polymer_drawmasks(void) // Both the top-level game drawrooms and the recursive internal passes // should be accounted for here. If these free cause corruption, there's // an accounting bug somewhere. - Bfree(cursectormaskcount); - cursectormaskcount = NULL; - Bfree(cursectormasks); - cursectormasks = NULL; + DO_FREE_AND_NULL(cursectormaskcount); + DO_FREE_AND_NULL(cursectormasks); } bglDisable(GL_CULL_FACE); @@ -2456,18 +2453,17 @@ static void polymer_freeboard(void) { if (prsectors[i]) { - if (prsectors[i]->verts) Bfree(prsectors[i]->verts); - if (prsectors[i]->floor.buffer) Bfree(prsectors[i]->floor.buffer); - if (prsectors[i]->ceil.buffer) Bfree(prsectors[i]->ceil.buffer); - if (prsectors[i]->floor.indices) Bfree(prsectors[i]->floor.indices); - if (prsectors[i]->ceil.indices) Bfree(prsectors[i]->ceil.indices); + Bfree(prsectors[i]->verts); + Bfree(prsectors[i]->floor.buffer); + Bfree(prsectors[i]->ceil.buffer); + Bfree(prsectors[i]->floor.indices); + Bfree(prsectors[i]->ceil.indices); if (prsectors[i]->ceil.vbo) bglDeleteBuffersARB(1, &prsectors[i]->ceil.vbo); if (prsectors[i]->ceil.ivbo) bglDeleteBuffersARB(1, &prsectors[i]->ceil.ivbo); if (prsectors[i]->floor.vbo) bglDeleteBuffersARB(1, &prsectors[i]->floor.vbo); if (prsectors[i]->floor.ivbo) bglDeleteBuffersARB(1, &prsectors[i]->floor.ivbo); - Bfree(prsectors[i]); - prsectors[i] = NULL; + DO_FREE_AND_NULL(prsectors[i]); } i++; @@ -2478,18 +2474,17 @@ static void polymer_freeboard(void) { if (prwalls[i]) { - if (prwalls[i]->bigportal) Bfree(prwalls[i]->bigportal); - if (prwalls[i]->mask.buffer) Bfree(prwalls[i]->mask.buffer); - if (prwalls[i]->over.buffer) Bfree(prwalls[i]->over.buffer); - //if (prwalls[i]->cap) Bfree(prwalls[i]->cap); - if (prwalls[i]->wall.buffer) Bfree(prwalls[i]->wall.buffer); + Bfree(prwalls[i]->bigportal); + Bfree(prwalls[i]->mask.buffer); + Bfree(prwalls[i]->over.buffer); + // Bfree(prwalls[i]->cap); + Bfree(prwalls[i]->wall.buffer); if (prwalls[i]->wall.vbo) bglDeleteBuffersARB(1, &prwalls[i]->wall.vbo); if (prwalls[i]->over.vbo) bglDeleteBuffersARB(1, &prwalls[i]->over.vbo); if (prwalls[i]->mask.vbo) bglDeleteBuffersARB(1, &prwalls[i]->mask.vbo); if (prwalls[i]->stuffvbo) bglDeleteBuffersARB(1, &prwalls[i]->stuffvbo); - Bfree(prwalls[i]); - prwalls[i] = NULL; + DO_FREE_AND_NULL(prwalls[i]); } i++; @@ -2500,10 +2495,9 @@ static void polymer_freeboard(void) { if (prsprites[i]) { - if (prsprites[i]->plane.buffer) Bfree(prsprites[i]->plane.buffer); + Bfree(prsprites[i]->plane.buffer); if (prsprites[i]->plane.vbo) bglDeleteBuffersARB(1, &prsprites[i]->plane.vbo); - Bfree(prsprites[i]); - prsprites[i] = NULL; + DO_FREE_AND_NULL(prsprites[i]); } i++; @@ -6196,8 +6190,7 @@ static void polymer_initrendertargets(int32_t count) bglDeleteFramebuffersEXT(1, &prrts[i].fbo); prrts[i].fbo = 0; } - Bfree(prrts); - prrts = NULL; + DO_FREE_AND_NULL(prrts); } ocount = 0; diff --git a/polymer/eduke32/build/src/scriptfile.c b/polymer/eduke32/build/src/scriptfile.c index c6faccdca..a9ee77fa7 100644 --- a/polymer/eduke32/build/src/scriptfile.c +++ b/polymer/eduke32/build/src/scriptfile.c @@ -313,11 +313,9 @@ scriptfile *scriptfile_fromstring(const char *string) void scriptfile_close(scriptfile *sf) { if (!sf) return; - if (sf->lineoffs) Bfree(sf->lineoffs); - if (sf->textbuf) Bfree(sf->textbuf); - if (sf->filename) Bfree(sf->filename); - sf->textbuf = NULL; - sf->filename = NULL; + Bfree(sf->lineoffs); + Bfree(sf->textbuf); + Bfree(sf->filename); Bfree(sf); } @@ -398,8 +396,7 @@ int32_t scriptfile_addsymbolvalue(char *name, int32_t val) void scriptfile_clearsymbols(void) { - if (symbtab) Bfree(symbtab); - symbtab = NULL; + DO_FREE_AND_NULL(symbtab); symbtablength = 0; symbtaballoclength = 0; } diff --git a/polymer/eduke32/build/src/texcache.c b/polymer/eduke32/build/src/texcache.c index fcfa1a61c..9e86a4869 100644 --- a/polymer/eduke32/build/src/texcache.c +++ b/polymer/eduke32/build/src/texcache.c @@ -208,8 +208,7 @@ void texcache_freeptrs(void) texcache.iptrs[ii] = NULL; } - Bfree(texcache.iptrs[i]); - texcache.iptrs[i] = NULL; + DO_FREE_AND_NULL(texcache.iptrs[i]); } DO_FREE_AND_NULL(texcache.iptrs); diff --git a/polymer/eduke32/build/src/util/arttool.cc b/polymer/eduke32/build/src/util/arttool.cc index 6c31b5a34..5d1c95a2f 100644 --- a/polymer/eduke32/build/src/util/arttool.cc +++ b/polymer/eduke32/build/src/util/arttool.cc @@ -120,10 +120,7 @@ unsigned Bstring::length(void) const { return Bstrlen(data); } void Bstring::clear(void) { - if (data != NULL) - Bfree(data); - - data = NULL; + DO_FREE_AND_NULL(data); } ////////// arttool ////////// diff --git a/polymer/eduke32/build/src/winlayer.c b/polymer/eduke32/build/src/winlayer.c index c7f8d35af..aa5bc39b1 100644 --- a/polymer/eduke32/build/src/winlayer.c +++ b/polymer/eduke32/build/src/winlayer.c @@ -464,7 +464,7 @@ int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, in win_close(); - if (argvbuf) Bfree(argvbuf); + Bfree(argvbuf); return r; } @@ -1158,18 +1158,18 @@ static void UninitDirectInput(void) if (axisdefs) { - for (i=joynumaxes-1; i>=0; i--) if (axisdefs[i].name) Bfree((void *)axisdefs[i].name); - Bfree(axisdefs); axisdefs = NULL; + for (i=joynumaxes-1; i>=0; i--) Bfree(axisdefs[i].name); + DO_FREE_AND_NULL(axisdefs); } if (buttondefs) { - for (i=joynumbuttons-1; i>=0; i--) if (buttondefs[i].name) Bfree((void *)buttondefs[i].name); - Bfree(buttondefs); buttondefs = NULL; + for (i=joynumbuttons-1; i>=0; i--) Bfree(buttondefs[i].name); + DO_FREE_AND_NULL(buttondefs); } if (hatdefs) { - for (i=joynumhats-1; i>=0; i--) if (hatdefs[i].name) Bfree((void *)hatdefs[i].name); - Bfree(hatdefs); hatdefs = NULL; + for (i=joynumhats-1; i>=0; i--) Bfree(hatdefs[i].name); + DO_FREE_AND_NULL(hatdefs); } if (di_inputevt) @@ -2429,11 +2429,10 @@ static void ReleaseDirectDrawSurfaces(void) lpDDSPrimary = NULL; } - if (lpOffscreen) + // if (lpOffscreen) { // initprintf(" - Freeing offscreen buffer\n"); - Bfree(lpOffscreen); - lpOffscreen = NULL; + DO_FREE_AND_NULL(lpOffscreen); } } diff --git a/polymer/eduke32/source/animvpx.c b/polymer/eduke32/source/animvpx.c index a9d883cca..01f740c5b 100644 --- a/polymer/eduke32/source/animvpx.c +++ b/polymer/eduke32/source/animvpx.c @@ -146,8 +146,7 @@ int32_t animvpx_uninit_codec(animvpx_codec_ctx *codec) if (codec->initstate <= 0) return 2; - Bfree(codec->pic); - codec->pic = NULL; + DO_FREE_AND_NULL(codec->pic); if (vpx_codec_destroy(&codec->codec)) { diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index baff6fb65..32c966dc8 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -8352,8 +8352,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) } else { - Bfree(testplay_addparam); - testplay_addparam = NULL; + DO_FREE_AND_NULL(testplay_addparam); } } @@ -8501,11 +8500,7 @@ static int32_t osdcmd_testplay_addparam(const osdfuncparm_t *parm) } else { - if (testplay_addparam) - { - Bfree(testplay_addparam); - testplay_addparam = NULL; - } + DO_FREE_AND_NULL(testplay_addparam); } return OSDCMD_OK; @@ -8829,8 +8824,7 @@ static void SaveInHistory(const char *commandstr) if (dosave) { - if (scripthist[scripthistend]) - Bfree(scripthist[scripthistend]); + Bfree(scripthist[scripthistend]); scripthist[scripthistend] = Xstrdup(commandstr); scripthistend++; scripthistend %= SCRIPTHISTSIZ; @@ -9552,10 +9546,8 @@ static int32_t loadtilegroups(const char *fn) for (i=0; i= 0; i--) { - if (s_TileGroups[i].pIds != NULL) - Bfree(s_TileGroups[i].pIds); - if (s_TileGroups[i].szText != NULL) - Bfree(s_TileGroups[i].szText); + Bfree(s_TileGroups[i].pIds); + Bfree(s_TileGroups[i].szText); } for (i = numhelppages-1; i >= 0; i--) Bfree(helppage[i]); - if (helppage) Bfree(helppage); + Bfree(helppage); #endif } diff --git a/polymer/eduke32/source/common.c b/polymer/eduke32/source/common.c index ffc883ae1..0174894e9 100644 --- a/polymer/eduke32/source/common.c +++ b/polymer/eduke32/source/common.c @@ -46,15 +46,13 @@ char *g_scriptNamePtr = NULL; void clearGrpNamePtr(void) { - if (g_grpNamePtr != NULL) - Bfree(g_grpNamePtr); + Bfree(g_grpNamePtr); // g_grpNamePtr assumed to be assigned to right after } void clearScriptNamePtr(void) { - if (g_scriptNamePtr != NULL) - Bfree(g_scriptNamePtr); + Bfree(g_scriptNamePtr); // g_scriptNamePtr assumed to be assigned to right after } diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 8a8770ee5..7f0e72d87 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -10844,36 +10844,36 @@ static void G_Cleanup(void) for (i=(MAXLEVELS*(MAXVOLUMES+1))-1; i>=0; i--) // +1 volume for "intro", "briefing" music { - if (MapInfo[i].name != NULL) Bfree(MapInfo[i].name); - if (MapInfo[i].filename != NULL) Bfree(MapInfo[i].filename); - if (MapInfo[i].musicfn != NULL) Bfree(MapInfo[i].musicfn); + Bfree(MapInfo[i].name); + Bfree(MapInfo[i].filename); + Bfree(MapInfo[i].musicfn); G_FreeMapState(i); } for (i=MAXQUOTES-1; i>=0; i--) { - if (ScriptQuotes[i] != NULL) Bfree(ScriptQuotes[i]); - if (ScriptQuoteRedefinitions[i] != NULL) Bfree(ScriptQuoteRedefinitions[i]); + Bfree(ScriptQuotes[i]); + Bfree(ScriptQuoteRedefinitions[i]); } for (i=MAXPLAYERS-1; i>=0; i--) { - if (g_player[i].ps != NULL) Bfree(g_player[i].ps); - if (g_player[i].sync != NULL) Bfree(g_player[i].sync); + Bfree(g_player[i].ps); + Bfree(g_player[i].sync); } for (i=MAXSOUNDS-1; i>=0; i--) { - if (g_sounds[i].filename != NULL) Bfree(g_sounds[i].filename); + Bfree(g_sounds[i].filename); } #if !defined LUNATIC - if (label != NULL && label != (char *)&sprite[0]) Bfree(label); - if (labelcode != NULL && labelcode != (int32_t *)§or[0]) Bfree(labelcode); - if (script != NULL) Bfree(script); - if (bitptr != NULL) Bfree(bitptr); + if (label != (char *)&sprite[0]) Bfree(label); + if (labelcode != (int32_t *)§or[0]) Bfree(labelcode); + Bfree(script); + Bfree(bitptr); -// if (MusicPtr != NULL) Bfree(MusicPtr); +// Bfree(MusicPtr); hash_free(&h_gamevars); hash_free(&h_arrays); @@ -11702,8 +11702,8 @@ int32_t app_main(int32_t argc, const char **argv) for (i=0; i < g_defModulesNum; ++i) Bfree(g_defModules[i]); - Bfree(g_defModules); - g_defModules = NULL; + DO_FREE_AND_NULL(g_defModules); + g_defModulesNum = 0; if (E_PostInit()) G_FatalEngineError(); @@ -11795,9 +11795,9 @@ int32_t app_main(int32_t argc, const char **argv) initprintf("There was an error loading the sprite clipping map (status %d).\n", i); for (i=0; i < g_clipMapFilesNum; ++i) - Bfree (g_clipMapFiles[i]); - Bfree (g_clipMapFiles); - g_clipMapFiles = NULL; + Bfree(g_clipMapFiles[i]); + DO_FREE_AND_NULL(g_clipMapFiles); + g_clipMapFilesNum = 0; #endif // check if the minifont will support lowercase letters (3136-3161) diff --git a/polymer/eduke32/source/gamedef.c b/polymer/eduke32/source/gamedef.c index 47e0d3f26..8925e72ea 100644 --- a/polymer/eduke32/source/gamedef.c +++ b/polymer/eduke32/source/gamedef.c @@ -2425,14 +2425,8 @@ void C_UndefineLevel(int32_t vol, int32_t lev) { map_t *const map = &MapInfo[(MAXLEVELS*vol)+lev]; - if (map->filename) - Bfree(map->filename); - map->filename = NULL; - - if (map->name) - Bfree(map->name); - map->name = NULL; - + DO_FREE_AND_NULL(map->filename); + DO_FREE_AND_NULL(map->name); map->partime = 0; map->designertime = 0; } @@ -2460,8 +2454,8 @@ void C_AllocProjectile(int32_t j) void C_FreeProjectile(int32_t j) { - Bfree(g_tile[j].proj); - g_tile[j].proj = g_tile[j].defproj = NULL; + DO_FREE_AND_NULL(g_tile[j].proj); + g_tile[j].defproj = NULL; } @@ -6601,8 +6595,7 @@ void C_Compile(const char *filenam) kread(fp,(char *)textptr,fs); kclose(fp); - if (script != NULL) - Bfree(script); + Bfree(script); script = (intptr_t *)Xcalloc(1,g_scriptSize * sizeof(intptr_t)); bitptr = (char *)Xcalloc(1,(((g_scriptSize+7)>>3)+1) * sizeof(uint8_t)); @@ -6626,8 +6619,7 @@ void C_Compile(const char *filenam) C_Include(g_scriptModules[i]); Bfree(g_scriptModules[i]); } - Bfree(g_scriptModules); - g_scriptModules = NULL; + DO_FREE_AND_NULL(g_scriptModules); g_scriptModulesNum = 0; flushlogwindow = 1; @@ -6637,8 +6629,7 @@ void C_Compile(const char *filenam) //*script = (intptr_t) g_scriptPtr; - Bfree(mptr); - mptr = NULL; + DO_FREE_AND_NULL(mptr); if (g_numCompilerWarnings|g_numCompilerErrors) initprintf("Found %d warning(s), %d error(s).\n",g_numCompilerWarnings,g_numCompilerErrors); diff --git a/polymer/eduke32/source/grpscan.c b/polymer/eduke32/source/grpscan.c index 1ce060337..d3ce07151 100644 --- a/polymer/eduke32/source/grpscan.c +++ b/polymer/eduke32/source/grpscan.c @@ -232,12 +232,8 @@ static void FreeGameList(void) while (listgrps) { Bfree(listgrps->name); - - if (listgrps->scriptname) - Bfree(listgrps->scriptname); - - if (listgrps->defname) - Bfree(listgrps->defname); + Bfree(listgrps->scriptname); + Bfree(listgrps->defname); grpinfo_t * const fg = listgrps->next; Bfree(listgrps); diff --git a/polymer/eduke32/source/jaudiolib/src/driver_sdl.c b/polymer/eduke32/source/jaudiolib/src/driver_sdl.c index 71a80d73f..ae7b628a6 100644 --- a/polymer/eduke32/source/jaudiolib/src/driver_sdl.c +++ b/polymer/eduke32/source/jaudiolib/src/driver_sdl.c @@ -212,11 +212,7 @@ void SDLDrv_PCM_Shutdown(void) DummyChunk = NULL; } - if (DummyBuffer != NULL) - { - free(DummyBuffer); - DummyBuffer = NULL; - } + DO_FREE_AND_NULL(DummyBuffer); Mix_CloseAudio(); diff --git a/polymer/eduke32/source/jaudiolib/src/flac.c b/polymer/eduke32/source/jaudiolib/src/flac.c index 9cf45370d..dddf23f0a 100644 --- a/polymer/eduke32/source/jaudiolib/src/flac.c +++ b/polymer/eduke32/source/jaudiolib/src/flac.c @@ -658,8 +658,7 @@ void MV_ReleaseFLACVoice(VoiceNode *voice) FLAC__stream_decoder_finish(fd->stream); FLAC__stream_decoder_delete(fd->stream); } - if (fd->block != NULL) - free(fd->block); + free(fd->block); free(fd); voice->rawdataptr = 0; diff --git a/polymer/eduke32/source/jaudiolib/src/xa.c b/polymer/eduke32/source/jaudiolib/src/xa.c index 5ca1febd2..13df0bcff 100644 --- a/polymer/eduke32/source/jaudiolib/src/xa.c +++ b/polymer/eduke32/source/jaudiolib/src/xa.c @@ -521,8 +521,7 @@ void MV_ReleaseXAVoice( VoiceNode * voice ) return; } - if (xad->block != NULL) - free(xad->block); + free(xad->block); free(xad); voice->rawdataptr = 0; diff --git a/polymer/eduke32/source/jmact/animlib.c b/polymer/eduke32/source/jmact/animlib.c index de37d0560..a96285e22 100644 --- a/polymer/eduke32/source/jmact/animlib.c +++ b/polymer/eduke32/source/jmact/animlib.c @@ -316,8 +316,7 @@ int32_t ANIM_LoadAnim(const uint8_t *buffer, int32_t length) void ANIM_FreeAnim(void) { - Bfree(anim); - anim = NULL; + DO_FREE_AND_NULL(anim); } diff --git a/polymer/eduke32/source/jmact/file_lib.c b/polymer/eduke32/source/jmact/file_lib.c index 0ebb58d24..899893041 100644 --- a/polymer/eduke32/source/jmact/file_lib.c +++ b/polymer/eduke32/source/jmact/file_lib.c @@ -69,7 +69,7 @@ int32_t SafeOpen(const char *filename, int32_t mode, int32_t sharemode) if (h < MaxFiles) { - if (FileNames[h]) Bfree(FileNames[h]); + Bfree(FileNames[h]); FileNames[h] = (char*)Xmalloc(strlen(filename)+1); strcpy(FileNames[h], filename); } @@ -105,8 +105,7 @@ void SafeClose(int32_t handle) if (handle < MaxFiles && FileNames[handle]) { - Bfree(FileNames[handle]); - FileNames[handle] = NULL; + DO_FREE_AND_NULL(FileNames[handle]); } } diff --git a/polymer/eduke32/source/jmact/scriplib.c b/polymer/eduke32/source/jmact/scriplib.c index dc53447d4..8989a8940 100644 --- a/polymer/eduke32/source/jmact/scriplib.c +++ b/polymer/eduke32/source/jmact/scriplib.c @@ -101,20 +101,14 @@ void SCRIPT_FreeSection(ScriptSectionType * section) { e = section->entries->nextentry; - if (section->entries->name) - Bfree(section->entries->name); - if (section->entries->value) - Bfree(section->entries->value); - + Bfree(section->entries->name); + Bfree(section->entries->value); Bfree(section->entries); section->entries = e; } - if (section->entries->name) - Bfree(section->entries->name); - if (section->entries->value) - Bfree(section->entries->value); - + Bfree(section->entries->name); + Bfree(section->entries->value); Bfree(section->entries); Bfree(section->name); } @@ -227,7 +221,7 @@ void SCRIPT_AddEntry(int32_t scripthandle, const char * sectionname, const char } } - if (e->value) Bfree(e->value); + Bfree(e->value); e->value = Bstrdup(entryvalue); } diff --git a/polymer/eduke32/source/lunatic/lunatic_game.c b/polymer/eduke32/source/lunatic/lunatic_game.c index 6cd14e619..1a58ee310 100644 --- a/polymer/eduke32/source/lunatic/lunatic_game.c +++ b/polymer/eduke32/source/lunatic/lunatic_game.c @@ -284,10 +284,7 @@ void El_ClearErrors(void) { int32_t i; for (i=0; i=0) { // the label gets assigned to a new tag number ('tag deleted') - Bfree(g_taglab.label[olabeltag]); - g_taglab.label[olabeltag] = NULL; + DO_FREE_AND_NULL(g_taglab.label[olabeltag]); diddel |= 2; } } @@ -1432,10 +1426,7 @@ static void M_Clear(StatusBarMenu *m) Bmemset(m->name, 0, sizeof(m->name)); for (i=0; idescription[i]); - m->description[i] = NULL; - } + DO_FREE_AND_NULL(m->description[i]); } static int32_t M_HaveDescription(StatusBarMenu *m) diff --git a/polymer/eduke32/source/m32def.c b/polymer/eduke32/source/m32def.c index 22bd7a880..239905a4a 100644 --- a/polymer/eduke32/source/m32def.c +++ b/polymer/eduke32/source/m32def.c @@ -1810,9 +1810,7 @@ static int32_t C_ParseCommand(void) statesinfo[j].numlocals = 0; Bsprintf(g_szCurrentBlockName, "%s", statesinfo[j].name); - if (cs.curStateMenuName) - Bfree(cs.curStateMenuName); - cs.curStateMenuName = NULL; + DO_FREE_AND_NULL(cs.curStateMenuName); if (C_GetKeyword() < 0) { @@ -1953,8 +1951,7 @@ static int32_t C_ParseCommand(void) if (cs.curStateMenuName) { registerMenuFunction(cs.curStateMenuName, j); - Bfree(cs.curStateMenuName); - cs.curStateMenuName = NULL; + DO_FREE_AND_NULL(cs.curStateMenuName); } g_didDefineSomething = 1; @@ -3753,8 +3750,7 @@ void C_Compile(const char *filenameortext, int32_t isfilename) //*script = g_scriptPtr-script; - if (mptr) - Bfree(mptr); + Bfree(mptr); if (g_stateCount > ostateCount) { diff --git a/polymer/eduke32/source/m32vars.c b/polymer/eduke32/source/m32vars.c index 14fc23283..742844ffc 100644 --- a/polymer/eduke32/source/m32vars.c +++ b/polymer/eduke32/source/m32vars.c @@ -42,11 +42,8 @@ static void Gv_Clear(void) { DO_FREE_AND_NULL(aGameVars[i].szLabel); - if ((aGameVars[i].dwFlags & GAMEVAR_USER_MASK) && aGameVars[i].val.plValues) - { - Bfree(aGameVars[i].val.plValues); - aGameVars[i].val.plValues = NULL; - } + if (aGameVars[i].dwFlags & GAMEVAR_USER_MASK) + DO_FREE_AND_NULL(aGameVars[i].val.plValues); aGameVars[i].val.lValue = 0; aGameVars[i].dwFlags |= GAMEVAR_RESET; @@ -58,11 +55,8 @@ static void Gv_Clear(void) DO_FREE_AND_NULL(gar->szLabel); - if ((gar->dwFlags & GAMEARRAY_NORMAL) && gar->vals) - { - Bfree(gar->vals); - gar->vals = NULL; - } + if (gar->dwFlags & GAMEARRAY_NORMAL) + DO_FREE_AND_NULL(gar->vals); gar->dwFlags |= GAMEARRAY_RESET; } @@ -194,9 +188,7 @@ int32_t Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags) if (aGameVars[i].dwFlags & GAMEVAR_USER_MASK) { // only free if not system - if (aGameVars[i].val.plValues) - Bfree(aGameVars[i].val.plValues); - aGameVars[i].val.plValues = NULL; + DO_FREE_AND_NULL(aGameVars[i].val.plValues); } } diff --git a/polymer/eduke32/source/midi.c b/polymer/eduke32/source/midi.c index e5450f0e6..06a5f00fa 100644 --- a/polymer/eduke32/source/midi.c +++ b/polymer/eduke32/source/midi.c @@ -1163,9 +1163,8 @@ void MIDI_StopSong _MIDI_Funcs->ReleasePatches(); } - Bfree(_MIDI_TrackPtr); + DO_FREE_AND_NULL(_MIDI_TrackPtr); - _MIDI_TrackPtr = NULL; _MIDI_NumTracks = 0; _MIDI_TrackMemSize = 0; @@ -1252,9 +1251,8 @@ int32_t MIDI_PlaySong { if (B_UNBUF32(ptr) != MIDI_TRACK_SIGNATURE) { - Bfree(_MIDI_TrackPtr); + DO_FREE_AND_NULL(_MIDI_TrackPtr); - _MIDI_TrackPtr = NULL; _MIDI_TrackMemSize = 0; return(MIDI_InvalidTrack); diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index 3555fbdb6..11399dbd2 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -1454,11 +1454,7 @@ end_vol4a: Gv_ResetSystemDefaults(); for (i=0; i<(MAXVOLUMES*MAXLEVELS); i++) - if (MapInfo[i].savedstate) - { - Baligned_free(MapInfo[i].savedstate); - MapInfo[i].savedstate = NULL; - } + ALIGNED_FREE_AND_NULL(MapInfo[i].savedstate); if (ud.m_coop != 1) { @@ -2058,10 +2054,7 @@ void G_FreeMapState(int32_t mapnum) { if (aGameVars[j].dwFlags & GAMEVAR_NORESET) continue; if (aGameVars[j].dwFlags & (GAMEVAR_PERPLAYER|GAMEVAR_PERACTOR)) - { - if (mapinfo->savedstate->vars[j]) - Baligned_free(mapinfo->savedstate->vars[j]); - } + Baligned_free(mapinfo->savedstate->vars[j]); } #else Bfree(mapinfo->savedstate->savecode); diff --git a/polymer/eduke32/source/savegame.c b/polymer/eduke32/source/savegame.c index 9ed1a8676..6cbd1a260 100644 --- a/polymer/eduke32/source/savegame.c +++ b/polymer/eduke32/source/savegame.c @@ -1647,8 +1647,7 @@ static void sv_prescriptsave_once() } static void sv_prescriptload_once() { - if (script) - Bfree(script); + Bfree(script); script = (intptr_t *)Xmalloc(g_scriptSize * sizeof(script[0])); } static void sv_postscript_once() diff --git a/polymer/eduke32/source/startwin.game.c b/polymer/eduke32/source/startwin.game.c index 81eead20a..a3e8ffe6c 100644 --- a/polymer/eduke32/source/startwin.game.c +++ b/polymer/eduke32/source/startwin.game.c @@ -788,7 +788,7 @@ int32_t startwin_run(void) for (e=wavedevs->devs; e; e=d) { d = e->next; - if (e->devs) Bfree(e->devs); + Bfree(e->devs); Bfree(e); } Bfree(wavedevs); diff --git a/polymer/eduke32/source/sw/src/common.c b/polymer/eduke32/source/sw/src/common.c index ea767a16b..f6306a7f7 100644 --- a/polymer/eduke32/source/sw/src/common.c +++ b/polymer/eduke32/source/sw/src/common.c @@ -11,8 +11,7 @@ char *g_grpNamePtr = NULL; void clearGrpNamePtr(void) { - if (g_grpNamePtr != NULL) - Bfree(g_grpNamePtr); + Bfree(g_grpNamePtr); // g_grpNamePtr assumed to be assigned to right after } diff --git a/polymer/eduke32/source/sw/src/game.c b/polymer/eduke32/source/sw/src/game.c index b905ee6fd..01eed108a 100644 --- a/polymer/eduke32/source/sw/src/game.c +++ b/polymer/eduke32/source/sw/src/game.c @@ -1034,8 +1034,8 @@ InitGame(int32_t argc, const char **argv) for (i=0; i < g_defModulesNum; ++i) Bfree(g_defModules[i]); - Bfree(g_defModules); - g_defModules = NULL; + DO_FREE_AND_NULL(g_defModules); + g_defModulesNum = 0; if (E_PostInit()) SW_FatalEngineError(); diff --git a/polymer/eduke32/source/sw/src/scrip2.c b/polymer/eduke32/source/sw/src/scrip2.c index ead818606..faf1beab2 100644 --- a/polymer/eduke32/source/sw/src/scrip2.c +++ b/polymer/eduke32/source/sw/src/scrip2.c @@ -628,7 +628,7 @@ void LoadCustomInfoFromScript(char *filename) char *t; if (scriptfile_getstring(script, &t)) break; - if (custommaps[curmap].LevelName) free(custommaps[curmap].LevelName); + Bfree(custommaps[curmap].LevelName); custommaps[curmap].LevelName = strdup(t); LevelInfo[curmap].LevelName = custommaps[curmap].LevelName; break; @@ -638,7 +638,7 @@ void LoadCustomInfoFromScript(char *filename) char *t; if (scriptfile_getstring(script, &t)) break; - if (custommaps[curmap].SongName) free(custommaps[curmap].SongName); + Bfree(custommaps[curmap].SongName); custommaps[curmap].SongName = strdup(t); LevelInfo[curmap].SongName = custommaps[curmap].SongName; break; @@ -648,7 +648,7 @@ void LoadCustomInfoFromScript(char *filename) char *t; if (scriptfile_getstring(script, &t)) break; - if (custommaps[curmap].Description) free(custommaps[curmap].Description); + Bfree(custommaps[curmap].Description); custommaps[curmap].Description = strdup(t); LevelInfo[curmap].Description = custommaps[curmap].Description; break; @@ -660,7 +660,7 @@ void LoadCustomInfoFromScript(char *filename) if (scriptfile_getnumber(script, &n)) break; Bsnprintf(s, 10, "%d : %02d", n/60, n%60); - if (custommaps[curmap].BestTime) free(custommaps[curmap].BestTime); + Bfree(custommaps[curmap].BestTime); custommaps[curmap].BestTime = strdup(s); LevelInfo[curmap].BestTime = custommaps[curmap].BestTime; break; @@ -672,7 +672,7 @@ void LoadCustomInfoFromScript(char *filename) if (scriptfile_getnumber(script, &n)) break; Bsnprintf(s, 10, "%d : %02d", n/60, n%60); - if (custommaps[curmap].ParTime) free(custommaps[curmap].ParTime); + Bfree(custommaps[curmap].ParTime); custommaps[curmap].ParTime = strdup(s); LevelInfo[curmap].ParTime = custommaps[curmap].ParTime; break; @@ -882,7 +882,7 @@ void LoadCustomInfoFromScript(char *filename) if (name) { - if (custominventoryname[in]) free(custominventoryname[in]); + Bfree(custominventoryname[in]); custominventoryname[in] = strdup(name); InventoryDecls[in].name = custominventoryname[in]; } @@ -956,7 +956,7 @@ void LoadCustomInfoFromScript(char *filename) if (maxammo >= 0) DamageData[id].max_ammo = maxammo; if (name) { - if (customweaponname[0][id]) free(customweaponname[0][id]); + Bfree(customweaponname[0][id]); customweaponname[0][id] = strdup(name); DamageData[id].weapon_name = customweaponname[0][id]; } @@ -966,7 +966,7 @@ void LoadCustomInfoFromScript(char *filename) { if (ammo) { - if (customweaponname[1][id]) free(customweaponname[1][id]); + Bfree(customweaponname[1][id]); customweaponname[1][id] = strdup(ammo); DamageData[id].ammo_name = customweaponname[1][id]; } diff --git a/polymer/eduke32/source/sw/src/sounds.c b/polymer/eduke32/source/sw/src/sounds.c index 314a8eab8..7498091e8 100644 --- a/polymer/eduke32/source/sw/src/sounds.c +++ b/polymer/eduke32/source/sw/src/sounds.c @@ -543,11 +543,7 @@ StopSong(void) } SongType = SongTypeNone; - if (SongName) - { - free(SongName); - } - SongName = 0; + DO_FREE_AND_NULL(SongName); SongTrack = 0; if (SongPtr)