From 8f3b7158e3b574591aa739320c7fe7b7acf92a3a Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 7 Dec 2025 18:57:56 +0100 Subject: [PATCH 1/7] w_wad: kill longname support we dont use it for anything, we also cannot use it for anything. Due to massive amounts of unterminated string being passed to everything So we dont need to waste memory and resources --- src/w_wad.cpp | 26 +++++++++++++------------- src/w_wad.h | 12 ++++++------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/w_wad.cpp b/src/w_wad.cpp index 27de24789..8afb38cab 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -144,7 +144,7 @@ void W_Shutdown(void) Z_Free(wad->filename); while (wad->numlumps--) { - Z_Free(wad->lumpinfo[wad->numlumps].longname); + //Z_Free(wad->lumpinfo[wad->numlumps].longname); Z_Free(wad->lumpinfo[wad->numlumps].fullname); } @@ -418,11 +418,11 @@ static lumpinfo_t* ResGetLumpsStandalone(FILE* handle, UINT16* numlumps, const c lumpinfo->hash.name = W_HashLumpName(lumpname); // Allocate the lump's long name. - lumpinfo->longname = static_cast(Z_Malloc((lumpinfo->namelength + 1) * sizeof(char), PU_STATIC, NULL)); + /*lumpinfo->longname = static_cast(Z_Malloc((lumpinfo->namelength + 1) * sizeof(char), PU_STATIC, NULL)); strcpy(lumpinfo->longname, lumpname); lumpinfo->longname[lumpinfo->namelength] = '\0'; lumpinfo->longnamelength = lumpinfo->namelength; - lumpinfo->hash.longname = lumpinfo->hash.name; + lumpinfo->hash.longname = lumpinfo->hash.name;*/ // Allocate the lump's full name. lumpinfo->fullname = static_cast(Z_Malloc((lumpinfo->namelength + 1) * sizeof(char), PU_STATIC, NULL)); @@ -529,11 +529,11 @@ static lumpinfo_t* ResGetLumpsWad(FILE* handle, UINT16* nlmp, const char* filena lump_p->hash.name = W_HashLumpName(lump_p->name); // Allocate the lump's long name. - lump_p->longname = static_cast(Z_Malloc(9 * sizeof(char), PU_STATIC, NULL)); + /*lump_p->longname = static_cast(Z_Malloc(9 * sizeof(char), PU_STATIC, NULL)); strncpy(lump_p->longname, fileinfo->name, 8); lump_p->longname[8] = '\0'; lump_p->longnamelength = lump_p->namelength; - lump_p->hash.longname = lump_p->hash.name; + lump_p->hash.longname = lump_p->hash.name;*/ // Allocate the lump's full name. lump_p->fullname = static_cast(Z_Malloc(9 * sizeof(char), PU_STATIC, NULL)); @@ -729,10 +729,10 @@ static lumpinfo_t* ResGetLumpsZip(FILE* handle, UINT16* nlmp) lump_p->namelength = strlen(lump_p->name); lump_p->hash.name = W_HashLumpName(lump_p->name); - lump_p->longname = static_cast(Z_Calloc(dotpos - trimname + 1, PU_STATIC, NULL)); + /*lump_p->longname = static_cast(Z_Calloc(dotpos - trimname + 1, PU_STATIC, NULL)); strlcpy(lump_p->longname, trimname, dotpos - trimname + 1); lump_p->longnamelength = strlen(lump_p->longname); - lump_p->hash.longname = W_HashLumpName(lump_p->longname); + lump_p->hash.longname = W_HashLumpName(lump_p->longname);*/ lump_p->fullname = static_cast(Z_Calloc(SHORT(zentry->namelen) + 1, PU_STATIC, NULL)); strncpy(lump_p->fullname, fullname, SHORT(zentry->namelen)); @@ -1124,7 +1124,7 @@ UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump) // Should be the only version, but that's not possible until we fix // all the instances of non null-terminated strings in the codebase... // -UINT16 W_CheckNumForLongNamePwad(const char *name, UINT16 wad, UINT16 startlump) +/*UINT16 W_CheckNumForLongNamePwad(const char *name, UINT16 wad, UINT16 startlump) { UINT16 i; UINT32 hash; @@ -1156,7 +1156,7 @@ UINT16 W_CheckNumForLongNamePwad(const char *name, UINT16 wad, UINT16 startlump) // not found. return INT16_MAX; -} +}*/ UINT16 W_CheckNumForMarkerStartPwad(const char *name, UINT16 wad, UINT16 startlump) { @@ -1306,7 +1306,7 @@ lumpnum_t W_CheckNumForName(const char *name) // Should be the only version, but that's not possible until we fix // all the instances of non null-terminated strings in the codebase... // -lumpnum_t W_CheckNumForLongName(const char *name) +/*lumpnum_t W_CheckNumForLongName(const char *name) { INT32 i; lumpnum_t check = INT16_MAX; @@ -1340,7 +1340,7 @@ lumpnum_t W_CheckNumForLongName(const char *name) return lumpnum; } -} +}*/ // // W_GetNumForName @@ -1365,7 +1365,7 @@ lumpnum_t W_GetNumForName(const char *name) // Should be the only version, but that's not possible until we fix // all the instances of non null-terminated strings in the codebase... // -lumpnum_t W_GetNumForLongName(const char *name) +/*lumpnum_t W_GetNumForLongName(const char *name) { lumpnum_t i; @@ -1375,7 +1375,7 @@ lumpnum_t W_GetNumForLongName(const char *name) I_Error("W_GetNumForLongName: %s not found!\n", name); return i; -} +}*/ // // W_CheckNumForNameInBlock diff --git a/src/w_wad.h b/src/w_wad.h index 9ed733f78..75c7e9c04 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -68,11 +68,11 @@ typedef struct unsigned long position; // filelump_t filepos unsigned long disksize; // filelump_t size char name[9]; // filelump_t name[] e.g. "LongEntr" - char *longname; // e.g. "LongEntryName" + //char *longname; // e.g. "LongEntryName" char *fullname; // e.g. "Folder/Subfolder/LongEntryName.extension" size_t namelength; // length of name - size_t longnamelength; // length of longname + //size_t longnamelength; // length of longname size_t fullnamelength; // length of fullname size_t size; // real (uncompressed) size @@ -80,7 +80,7 @@ typedef struct struct { UINT32 name; // hash of name - UINT32 longname; // hash of longname + //UINT32 longname; // hash of longname //UINT32 fullname; // hash of fullname } hash; } lumpinfo_t; @@ -180,7 +180,7 @@ const char *W_CheckNameForNumPwad(UINT16 wad, UINT16 lump); const char *W_CheckNameForNum(lumpnum_t lumpnum); UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump); // checks only in one pwad -UINT16 W_CheckNumForLongNamePwad(const char *name, UINT16 wad, UINT16 startlump); +//UINT16 W_CheckNumForLongNamePwad(const char *name, UINT16 wad, UINT16 startlump); /* Find the first lump after F_START for instance. */ UINT16 W_CheckNumForMarkerStartPwad(const char *name, UINT16 wad, UINT16 startlump); @@ -190,9 +190,9 @@ UINT16 W_CheckNumForFolderStartPK3(const char *name, UINT16 wad, UINT16 startlum UINT16 W_CheckNumForFolderEndPK3(const char *name, UINT16 wad, UINT16 startlump); lumpnum_t W_CheckNumForName(const char *name); -lumpnum_t W_CheckNumForLongName(const char *name); +//lumpnum_t W_CheckNumForLongName(const char *name); lumpnum_t W_GetNumForName(const char *name); // like W_CheckNumForName but I_Error on LUMPERROR -lumpnum_t W_GetNumForLongName(const char *name); +//lumpnum_t W_GetNumForLongName(const char *name); lumpnum_t W_CheckNumForNameInBlock(const char *name, const char *blockstart, const char *blockend); UINT8 W_LumpExists(const char *name); // Lua uses this. UINT8 W_CheckMultipleLumps(const char* lump, ...); // variadic version of above lmao From 25dd3b49762cc979f3ffe52395ff43446d3f0b5a Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 1 Dec 2025 23:00:22 +0100 Subject: [PATCH 2/7] Revert "Fix static memory being re-tagged as purgable" This reverts commit c544cf9a7cc5b6c21d20e71672273be02035df92. --- src/z_zone.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/z_zone.cpp b/src/z_zone.cpp index 549696bd7..9e5b4f41e 100644 --- a/src/z_zone.cpp +++ b/src/z_zone.cpp @@ -651,9 +651,6 @@ void Z_ChangeTag(void *ptr, INT32 tag) I_Error("Internal memory management error: " "tried to make block purgable but it has no owner"); - // No, please, don't make my PU_STATIC patch NULL! It supposed to be always valid! - if (block->tag < 10) return; - block->tag = tag; } From 40bd3e5e19d7dd853d65b0661e0bebece028cd82 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 26 Dec 2025 23:18:19 +0100 Subject: [PATCH 3/7] simplify opengl vsync set --- src/sdl/i_video.c | 14 +++++++------- src/sdl/ogl_sdl.c | 10 +--------- src/sdl/ogl_sdl.h | 2 +- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index c2d87e3f1..6be6bf638 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1426,7 +1426,7 @@ void I_FinishUpdate(void) #ifdef HWRENDER if (rendermode == render_opengl) { - OglSdlFinishUpdate(cv_vidwait.value); + OglSdlFinishUpdate(); return; } #endif @@ -2028,17 +2028,17 @@ UINT32 I_GetRefreshRate(void) static void Impl_SetVsync(void) { -#if SDL_VERSION_ATLEAST(2,0,18) - if (renderer) - SDL_RenderSetVSync(renderer, cv_vidwait.value); -#endif #ifdef HWRENDER - if (!renderer && rendermode == render_opengl && - sdlglcontext != NULL && SDL_GL_GetCurrentContext() == sdlglcontext) + if (rendermode == render_opengl && + sdlglcontext != NULL && SDL_GL_GetCurrentContext() == sdlglcontext) { SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); } #endif +#if SDL_VERSION_ATLEAST(2,0,18) + if (renderer) + SDL_RenderSetVSync(renderer, cv_vidwait.value); +#endif } void I_SetBorderlessWindow(void) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 319acab4b..4177c121a 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -241,22 +241,14 @@ boolean OglSdlSurface(INT32 w, INT32 h) \return void */ -void OglSdlFinishUpdate(boolean waitvbl) +void OglSdlFinishUpdate(void) { - static boolean oldwaitvbl = false; int sdlw, sdlh; #ifdef USE_FBO_OGL const boolean usefbo = UseScreenFBO(); #endif - if (oldwaitvbl != waitvbl) - { - SDL_GL_SetSwapInterval(waitvbl ? 1 : 0); - } - - oldwaitvbl = waitvbl; - SDL_GetWindowSize(window, &sdlw, &sdlh); HWR_MakeScreenFinalTexture(); diff --git a/src/sdl/ogl_sdl.h b/src/sdl/ogl_sdl.h index 6d614cd22..8dd2b9e0e 100644 --- a/src/sdl/ogl_sdl.h +++ b/src/sdl/ogl_sdl.h @@ -20,7 +20,7 @@ boolean OglSdlSurface(INT32 w, INT32 h); -void OglSdlFinishUpdate(boolean vidwait); +void OglSdlFinishUpdate(void); boolean VID_LoadOGLAPI(void); extern SDL_Renderer *renderer; From 1af1e42daba79f343dc0b42ba3b5788a1079b434 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 26 Dec 2025 23:20:30 +0100 Subject: [PATCH 4/7] FBO: remove nvidia xwayland hack this has been a non issue since a while now, so can remove this (we shouldnt work around driver bugs anyways) --- src/sdl/ogl_sdl.c | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 4177c121a..9e51efdc4 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -63,18 +63,9 @@ PFNglGetString pglGetString; #endif #ifdef USE_FBO_OGL - -#if defined (__unix__) -static boolean xwaylandcrap = false; -#endif - boolean UseScreenFBO(void) { - return ((supportFBO && cv_glframebuffer.value && downsample) -#if defined (__unix__) - || (supportFBO && xwaylandcrap) -#endif - ); + return (supportFBO && cv_glframebuffer.value && downsample); } #endif @@ -201,17 +192,6 @@ boolean OglSdlSurface(INT32 w, INT32 h) supportNPO2tex = true; glanisotropicmode_cons_t[1].value = maximumAnisotropy; - -#if defined (__unix__) -#ifdef USE_FBO_OGL - // TODO: delet this since nvidia fixed their shit on 575 - char videodriver[4] = {'S','D','L',0}; - if (supportFBO && strstr((const char*)gl_renderer, "NVIDIA") - && (*strncpy(videodriver, SDL_GetCurrentVideoDriver(), sizeof(videodriver)-1) != '\0') - && (strncasecmp("x11", videodriver, 4) == 0)) - xwaylandcrap = true; -#endif -#endif } SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); @@ -281,13 +261,6 @@ void OglSdlFinishUpdate(void) if (!I_CheckNativeRes() || WipeInAction) #endif HWR_DrawScreenFinalTexture(realwidth, realheight, false); - -#if defined (__unix__) -#ifdef USE_FBO_OGL - if (loaded_config) - xwaylandcrap = false; -#endif -#endif } #endif //HWRENDER From 7866b769cc542c6d9062cc022f4bf2d3afaa31e8 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sun, 21 Dec 2025 21:37:57 +0100 Subject: [PATCH 5/7] Do not archive table values for nil keys --- src/lua_script.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/lua_script.c b/src/lua_script.c index 96ce94a22..2aa88cd52 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1064,9 +1064,13 @@ static void ArchiveTables(UINT8 **p) { // Write key e = ArchiveValue(p, TABLESINDEX, -2); // key should be either a number or a string, ArchiveValue can handle this. - if (e == 2) // invalid key type (function, thread, lightuserdata, or anything we don't recognise) + if (e == 1) + n++; // the table contained a new table we'll have to archive. :( + else if (e == 2) // invalid key type (function, thread, lightuserdata, or anything we don't recognise) { CONS_Alert(CONS_ERROR, "Index '%s' (%s) of table %d could not be archived!\n", lua_tostring(gL, -2), luaL_typename(gL, -2), i); + lua_pop(gL, 1); + continue; } else if (e == 3) // nil key due to invalid userdata. NOT an error. { @@ -1077,15 +1081,12 @@ static void ArchiveTables(UINT8 **p) // Write value e = ArchiveValue(p, TABLESINDEX, -1); if (e == 1) - { n++; // the table contained a new table we'll have to archive. :( - } else if (e == 2) // invalid value type - { CONS_Alert(CONS_ERROR, "Type of value for table %d entry '%s' (%s) could not be archived!\n", i, lua_tostring(gL, -2), luaL_typename(gL, -1)); - } lua_pop(gL, 1); + } lua_pop(gL, 1); WRITEUINT8(*p, ARCH_TEND); @@ -1276,13 +1277,21 @@ static void UnArchiveTables(UINT8 **p, boolean network) UINT8 ret; ret = UnArchiveValue(p, TABLESINDEX, network); - if (ret == 3) + if (ret == 1) // End of table + break; + else if (ret == 2) // Key contains a new table + n++; + else if (ret == 3) { //CONS_Alert(CONS_WARNING,"Couldn't read mobj_t\n"); lua_pushnil(gL); } - else if (ret == 1) // read key - break; + + if (lua_isnil(gL, -1)) // If key is nil, skip this entry + { + lua_pop(gL, 1); + continue; + } ret = UnArchiveValue(p, TABLESINDEX, network); if (ret == 1) @@ -1291,21 +1300,15 @@ static void UnArchiveTables(UINT8 **p, boolean network) lua_pop(gL, 1); // Pop key break; } + else if (ret == 2) // read value + n++; else if (ret == 3) { //CONS_Alert(CONS_WARNING,"Couldn't read mobj_t\n"); lua_pushnil(gL); } - else if (ret == 2) // read value - n++; - if (lua_isnil(gL, -2)) // if key is nil (if a function etc was accidentally saved) - { - CONS_Alert(CONS_ERROR, "A nil key in table %d was found! (Invalid key type or corrupted save?)\n", i); - lua_pop(gL, 2); // pop key and value instead of setting them in the table, to prevent Lua panic errors - } - else - lua_rawset(gL, -3); + lua_rawset(gL, -3); } lua_pop(gL, 1); From 35e4f35f6e9867b3b143755a6c276a5946dee617 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Dec 2025 10:31:45 +0100 Subject: [PATCH 6/7] fix some shadowed variables, enable -Wshadow by default --- src/Makefile.d/versions.mk | 5 +---- src/hardware/hw_cache.cpp | 7 ++----- src/hardware/hw_main.cpp | 6 +++--- src/p_polyobj.c | 3 +-- src/r_segs.cpp | 10 +++++----- src/r_things.cpp | 2 +- 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk index 451ff72e7..48964c39f 100644 --- a/src/Makefile.d/versions.mk +++ b/src/Makefile.d/versions.mk @@ -20,7 +20,7 @@ $(foreach v,$(join $(wordlist 2,$(_n),- $(gcc_versions)),\ CXXFLAGS+= -Wno-aggregate-return # -W -Wno-unused -WFLAGS:=-Wall -Wno-trigraphs +WFLAGS:=-Wall -Wno-trigraphs -Wshadow ifndef GCC295 #WFLAGS+=-Wno-packed endif @@ -37,9 +37,6 @@ WFLAGS+=-Wfloat-equal ifndef GCC295 WFLAGS+=-Wendif-labels endif -ifdef GCC41 - WFLAGS+=-Wshadow -endif #WFLAGS+=-Wlarger-than-%len% WFLAGS+=-Wpointer-arith CWFLAGS+=-Wbad-function-cast diff --git a/src/hardware/hw_cache.cpp b/src/hardware/hw_cache.cpp index c20d7e9bb..09f4f1a7b 100644 --- a/src/hardware/hw_cache.cpp +++ b/src/hardware/hw_cache.cpp @@ -619,7 +619,6 @@ static void HWR_PrecacheLevelFlats(void) // lookup for flats that may´ve been already loaded // too lazy to make a hashtable or smth so unordered set will do :carbuncle: std::unordered_set flatpresent; - lumpnum_t lump; size_t i, j; INT32 k; @@ -649,9 +648,8 @@ static void HWR_PrecacheLevelFlats(void) const INT32 pic = ceiling ? sec->ceilingpic : sec->floorpic; const levelflat_t *levelflat = &levelflats[pic]; - lump = levelflat->lumpnum; - load_flat(lump, R_NoEncore(sec, ceiling)); + load_flat(levelflat->lumpnum, R_NoEncore(sec, ceiling)); if (levelflat->speed) // is it an animated flat ? { @@ -672,9 +670,8 @@ static void HWR_PrecacheLevelFlats(void) for (i = 0; i < numlevelflats; i++) { const levelflat_t *levelflat = &levelflats[i]; - lump = levelflat->lumpnum; - load_flat(lump, false); + load_flat(levelflat->lumpnum, false); if (levelflat->speed) // is it an animated flat ? { diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index afe899df2..70a5a3a8d 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -5538,7 +5538,7 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, bool player_t *viewplayer = &players[displayplayers[viewssnum]]; const float fpov = FixedToFloat(R_GetPlayerFov(viewplayer)); - auto reset_viewstate = [&](const float fpov) + auto reset_viewstate = [&]() { HWR_SetTransform(fpov); HWR_ClearSprites(); @@ -5558,7 +5558,7 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, bool currentportallist = &portallist; HWR_SetPortalState(GLPORTAL_SEARCH); - reset_viewstate(fpov); + reset_viewstate(); if (rootportal) { @@ -5584,7 +5584,7 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, bool // draw normal things in current frame in current incremented stencil buffer area HWR_SetStencilState(HWR_STENCIL_NORMAL, stencil_level); - reset_viewstate(fpov); + reset_viewstate(); if constexpr (Type == RenderViewpointType::kPortal) { diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 7b5135c9e..94c808b22 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1385,8 +1385,7 @@ static void Polyobj_rotateThings(polyobj_t *po, vector2_t origin, angle_t delta, if (mo->player) { - angle_t localangle = P_GetLocalAngle(mo->player); - P_ForceLocalAngle(mo->player, localangle + delta); + P_ForceLocalAngle(mo->player, P_GetLocalAngle(mo->player) + delta); } } } diff --git a/src/r_segs.cpp b/src/r_segs.cpp index c0aab2bfc..3fe8042ae 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -2229,12 +2229,12 @@ void R_StoreWallRange(INT32 start, INT32 stop) lowcutslope = std::max(worldbottomslope, worldlowslope) + viewz; highcutslope = std::min(worldtopslope, worldhighslope) + viewz; - auto check_fof_offscreen = [&](ffloor_t* rover, INT32 bottom, INT32 bottomslope, INT32 top, INT32 topslope) + auto check_fof_offscreen = [&](ffloor_t* rrover, INT32 bottom, INT32 bottomslope, INT32 top, INT32 topslope) { - return ((P_GetFFloorTopZAt (rover, segleft .x, segleft .y) <= bottom + viewz - && P_GetFFloorTopZAt (rover, segright.x, segright.y) <= bottomslope + viewz) - || ( P_GetFFloorBottomZAt (rover, segleft .x, segleft .y) >= top + viewz - && P_GetFFloorBottomZAt (rover, segright.x, segright.y) >= topslope + viewz)); + return ((P_GetFFloorTopZAt (rrover, segleft .x, segleft .y) <= bottom + viewz + && P_GetFFloorTopZAt (rrover, segright.x, segright.y) <= bottomslope + viewz) + || ( P_GetFFloorBottomZAt (rrover, segleft .x, segleft .y) >= top + viewz + && P_GetFFloorBottomZAt (rrover, segright.x, segright.y) >= topslope + viewz)); }; if (frontsector->ffloors && backsector->ffloors) diff --git a/src/r_things.cpp b/src/r_things.cpp index 489ce8911..b62d9e5d7 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -1577,7 +1577,7 @@ static void R_ProjectSprite(mobj_t *thing) else blendmode = thing->blendmode; - if (thing->flags2 & MF2_SHADOW || thing->flags2 & MF2_SHADOW) // actually only the player should use this (temporary invisibility) + if (thing->flags2 & MF2_SHADOW) // actually only the player should use this (temporary invisibility) trans = tr_trans80; // because now the translucency is set through FF_TRANSMASK else if (thing->frame & FF_TRANSMASK) { From b0bf588c27363f192b14e2b795fa7f761fce297b Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Dec 2025 10:52:21 +0100 Subject: [PATCH 7/7] fix some null pointer dereferences and enable -Wnull-dereference by default --- src/Makefile.d/versions.mk | 2 +- src/m_misc.c | 9 +++++---- src/s_sound.c | 3 +++ src/w_wad.c | 19 ++++++++++++++++++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk index 48964c39f..149fb30fc 100644 --- a/src/Makefile.d/versions.mk +++ b/src/Makefile.d/versions.mk @@ -20,7 +20,7 @@ $(foreach v,$(join $(wordlist 2,$(_n),- $(gcc_versions)),\ CXXFLAGS+= -Wno-aggregate-return # -W -Wno-unused -WFLAGS:=-Wall -Wno-trigraphs -Wshadow +WFLAGS:=-Wall -Wno-trigraphs -Wshadow -Wnull-dereference ifndef GCC295 #WFLAGS+=-Wno-packed endif diff --git a/src/m_misc.c b/src/m_misc.c index cbc40d4e2..8c7b34163 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1346,14 +1346,15 @@ void M_MinimapGenerate(void) minigen = AM_MinimapGenerate(mul); if (minigen == NULL || minigen->buf == NULL) - goto failure; + { + CONS_Alert(CONS_ERROR, M_GetText("Couldn't create %s\n"), filepath); + return; + } M_CreateScreenShotPalette(); ret = M_SavePNG(filepath, minigen->buf, minigen->w, minigen->h, screenshot_palette); -failure: - if (minigen->buf != NULL) - free(minigen->buf); + free(minigen->buf); if (ret) { diff --git a/src/s_sound.c b/src/s_sound.c index 5bc830252..e8075469c 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1491,6 +1491,9 @@ musicdef_t *S_FindMusicCredit(const char *musname) { def = S_GetMusicCredit(i); + if (!def) + continue; + if (hash != def->hash) continue; diff --git a/src/w_wad.c b/src/w_wad.c index 640ee0367..9be91c8ea 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1997,6 +1997,9 @@ void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag) rspr = (rotsprite_t *)W_GetCachedRotPatchPwad(WADFILENUM(num),LUMPNUM(num)); + if (rspr == NULL) + return W_CachePatchNum(W_GetNumForName("MISSING"), tag); + if (rspr->patches[idx] == NULL) { INT32 xpivot = 0, ypivot = 0; @@ -2612,6 +2615,9 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) // Remember that we're assuming that the WAD will have a specific set of lumps in a specific order. UINT8 *wadData = (UINT8*)(W_CacheLumpNum(lumpnum, PU_LEVEL)); + if (wadData == NULL) + I_Error("vres_GetMap: Invalid WadData!\n"); + filelump_t *fileinfo = (filelump_t *)(wadData + LONG(((wadinfo_t *)wadData)->infotableofs)); i = LONG(((wadinfo_t *)wadData)->numlumps); @@ -2628,6 +2634,8 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) } vlumps = (virtlump_t*)(Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL)); + if (vlumps == NULL) + I_Error("vres_GetMap: Out of memory!\n"); // Build the lumps, skipping over empty entries. for (i = 0, realentry = 0; i < numlumps; realentry++) @@ -2663,7 +2671,11 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) lumpnum_t lumppos = lumpnum + 1; for (i = LUMPNUM(lumppos); i < wadfiles[WADFILENUM(lumpnum)]->numlumps; i++, lumppos++, numlumps++) { - if (memcmp(W_CheckNameForNum(lumppos), "MAP", 3) == 0 || W_LumpLength(lumppos) == 0) + const char *name = W_CheckNameForNum(lumppos); + if (name == NULL) + continue; + + if (memcmp(name, "MAP", 3) == 0 || W_LumpLength(lumppos) == 0) { break; } @@ -2671,10 +2683,15 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) numlumps++; vlumps = (virtlump_t*)(Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL)); + if (vlumps == NULL) + I_Error("vres_GetMap: Out of memory!\n"); + for (i = 0; i < numlumps; i++, lumpnum++) { // Check if it is map marker. It is not always first lump sadly, so we need to expect it anywhere const char *name = W_CheckNameForNum(lumpnum); + if (name == NULL) + continue; if (strlen(name) == 5 && memcmp(name, "MAP", 3) == 0) {