From d8c9522ec95a070bd17c06fa68c3e4d441e1b493 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 29 May 2025 13:26:52 +0200 Subject: [PATCH] add a bunch of checks for if G_BuildMapTitle returns NULL --- src/command.c | 1 - src/d_netcmd.c | 9 +++++++-- src/discord.c | 14 ++++++++++---- src/g_game.c | 11 +++++++---- src/m_menu.c | 52 +++++++++++++++++++++++++++++++++----------------- src/s_sound.c | 9 ++++++--- 6 files changed, 65 insertions(+), 31 deletions(-) diff --git a/src/command.c b/src/command.c index e7dd9cc01..4e43e2cb5 100644 --- a/src/command.c +++ b/src/command.c @@ -240,7 +240,6 @@ void COM_ImmedExecute(const char *ptext) while (i < strlen(ptext)) { - quotes = 0; for (j = 0; i < strlen(ptext); i++,j++) { diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 862ebb679..1970b5323 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2774,7 +2774,7 @@ static void Command_Map_f(void) // G_TOLFlag handles both multiplayer gametype and ignores it for !multiplayer else { - if (!mapheaderinfo[newmapnum-1] || mapheaderinfo[newmapnum-1] == NULL) + if (!mapheaderinfo[newmapnum-1]) { CONS_Alert(CONS_WARNING, M_GetText("Invalid mapheaderinfo for Course %s (%s)\n"), realmapname, G_BuildMapName(newmapnum)); Z_Free(realmapname); @@ -3028,9 +3028,14 @@ static void Command_ReplayMarker(void) adjustedleveltime = 0; char *title = G_BuildMapTitle(gamemap); - snprintf(demo.titlename, 64, "%s [%i:%02d/%.5s]", title, G_TicsToMinutes(adjustedleveltime, false), G_TicsToSeconds(adjustedleveltime), modeattacking ? "Record Attack" : connectedservername); + if (title) + { + snprintf(demo.titlename, 64, "%s [%i:%02d/%.5s]", title, G_TicsToMinutes(adjustedleveltime, false), G_TicsToSeconds(adjustedleveltime), modeattacking ? "Record Attack" : connectedservername); Z_Free(title); + } + else + snprintf(demo.titlename, 64, "[%i:%02d/%.5s]", G_TicsToMinutes(adjustedleveltime, false), G_TicsToSeconds(adjustedleveltime), modeattacking ? "Record Attack" : connectedservername); CONS_Printf("Replay will be saved!\n"); } diff --git a/src/discord.c b/src/discord.c index cd7dafa8f..207a249a6 100644 --- a/src/discord.c +++ b/src/discord.c @@ -388,7 +388,7 @@ static void DRPC_GotServerIP(UINT32 address) --------------------------------------------------*/ static const char *DRPC_GetServerIP(void) { - const char *address; + const char *address; // If you're connected if (I_GetNodeAddress && (address = I_GetNodeAddress(servernode)) != NULL) @@ -489,7 +489,7 @@ void DRPC_UpdatePresence(void) { #endif discordPresence.state = "Private"; -#ifdef MASTERSERVER +#ifdef MASTERSERVER } #endif @@ -571,9 +571,15 @@ void DRPC_UpdatePresence(void) { // Map name on tool tip char *title = G_BuildMapTitle(gamemap); - snprintf(mapname, 48, "Map: %s", title); + if (title) + { + snprintf(mapname, 48, "Map: %s", title); + Z_Free(title); + } + else + snprintf(mapname, 48, "Map: UNKNOWN"); + discordPresence.largeImageText = mapname; - Z_Free(title); } if (gamestate == GS_LEVEL && Playing()) diff --git a/src/g_game.c b/src/g_game.c index 8a786929b..d5e41f6e0 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4001,7 +4001,6 @@ void G_InitNew(UINT8 pencoremode, const char *mapname, boolean resetplayer, bool } } - char *G_BuildMapTitle(INT32 mapnum) { char *title = NULL; @@ -6071,15 +6070,19 @@ void G_BeginRecording(void) char *title = G_BuildMapTitle(gamemap); // Print to a separate temp buffer instead of demo.titlename, so we can use it in M_TextInputSetString - snprintf(demotitlename, 64, "%s - %s", title, modeattacking ? "Time Attack" : connectedservername); + if (title) + { + snprintf(demotitlename, 64, "%s - %s", title, modeattacking ? "Time Attack" : connectedservername); + Z_Free(title); + } + else + snprintf(demotitlename, 64, "%s", modeattacking ? "Time Attack" : connectedservername); // Init just in case it isn't initialized already M_TextInputInit(&demo.titlenameinput, demo.titlename, sizeof(demo.titlename)); // This will indirectly assign to demo.titlename too M_TextInputSetString(&demo.titlenameinput, demotitlename); - - Z_Free(title); } // demo checksum diff --git a/src/m_menu.c b/src/m_menu.c index 8082c1e8c..9e207150c 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -7176,8 +7176,11 @@ static void DrawReplayHutReplayInfo(void) if (mapheaderinfo[demolist[dir_on[menudepthleft]].map-1]) { char *title = G_BuildMapTitle(demolist[dir_on[menudepthleft]].map); - V_DrawString(x, y, V_SNAPTOTOP|MENUCAPS, title); - Z_Free(title); + if (title) + { + V_DrawString(x, y, V_SNAPTOTOP|MENUCAPS, title); + Z_Free(title); + } } else V_DrawString(x, y, V_SNAPTOTOP|V_ALLOWLOWERCASE|V_TRANSLUCENT, "Level is not loaded."); @@ -8129,6 +8132,9 @@ UINT8 skyRoomMenuTranslations[MAXUNLOCKABLES]; static char *M_GetConditionString(condition_t cond) { + char *title = NULL; + char *response = NULL; + switch(cond.type) { case UC_PLAYTIME: @@ -8155,33 +8161,45 @@ static char *M_GetConditionString(condition_t cond) G_TicsToSeconds(cond.requirement)); case UC_MAPVISITED: { - char *title = G_BuildMapTitle(cond.requirement-1); - char *response = va("Visit %s", title); - Z_Free(title); + title = G_BuildMapTitle(cond.requirement-1); + if (title) + { + response = va("Visit %s", title); + Z_Free(title); + } return response; } case UC_MAPBEATEN: { - char *title = G_BuildMapTitle(cond.requirement-1); - char *response = va("Beat %s", title); - Z_Free(title); + title = G_BuildMapTitle(cond.requirement-1); + if (title) + { + response = va("Beat %s", title); + Z_Free(title); + } return response; } case UC_MAPALLEMERALDS: { - char *title = G_BuildMapTitle(cond.requirement-1); - char *response = va("Beat %s w/ all emeralds", title); - Z_Free(title); + title = G_BuildMapTitle(cond.requirement-1); + if (title) + { + response = va("Beat %s w/ all emeralds", title); + Z_Free(title); + } return response; } case UC_MAPTIME: { - char *title = G_BuildMapTitle(cond.extrainfo1-1); - char *response = va("Beat %s in %i:%02i.%02i", title, - G_TicsToMinutes(cond.requirement, true), - G_TicsToSeconds(cond.requirement), - G_TicsToCentiseconds(cond.requirement)); - Z_Free(title); + title = G_BuildMapTitle(cond.extrainfo1-1); + if (title) + { + response = va("Beat %s in %i:%02i.%02i", title, + G_TicsToMinutes(cond.requirement, true), + G_TicsToSeconds(cond.requirement), + G_TicsToCentiseconds(cond.requirement)); + Z_Free(title); + } return response; } case UC_TOTALEMBLEMS: diff --git a/src/s_sound.c b/src/s_sound.c index 922d864d5..cf75df56a 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2042,9 +2042,12 @@ static boolean S_SkipIntroMusic(void) char *maptitle = G_BuildMapTitle(gamemap); // Zzz... - // check if menu music is playing, otherwise it may continue playing - if (!stricmp(music.name, "titles") || (maptitle && (!stricmp(maptitle, "Wandering Falls")))) // wandering balls changes its song when the race starts Zzz... - skip = false; + if (maptitle) + { + // check if menu music is playing, otherwise it may continue playing + if (!stricmp(music.name, "titles") || (maptitle && (!stricmp(maptitle, "Wandering Falls")))) // wandering balls changes its song when the race starts Zzz... + skip = false; + } Z_Free(maptitle);