From 111548668998d0bc65b572c632f54eda24e3d5ea Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Fri, 9 Apr 2021 23:15:44 -0400 Subject: [PATCH] Fix crashes & off-by-one errors --- src/k_hud.c | 10 ++++++---- src/lua_hudlib.c | 11 +++++++---- src/m_menu.c | 21 ++++++++++++--------- src/w_wad.c | 6 ++++++ src/y_inter.c | 2 +- 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/k_hud.c b/src/k_hud.c index 1f2465152..ce8538939 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -3015,7 +3015,7 @@ static void K_drawKartMinimapIcon(fixed_t objx, fixed_t objy, INT32 hudx, INT32 static void K_drawKartMinimap(void) { - INT32 lumpnum = LUMPERROR; + lumpnum_t lumpnum = LUMPERROR; patch_t *AutomapPic; INT32 i = 0; INT32 x, y; @@ -3042,10 +3042,12 @@ static void K_drawKartMinimap(void) lumpnum = W_CheckNumForLongName(mapheaderinfo[gamemap-1]->minimapLump); } - if (lumpnum != -1) - AutomapPic = W_CachePatchNum(lumpnum, PU_HUDGFX); - else + if (lumpnum == LUMPERROR) + { return; // no pic, just get outta here + } + + AutomapPic = W_CachePatchNum(lumpnum, PU_HUDGFX); x = MINI_X - (AutomapPic->width/2); y = MINI_Y - (AutomapPic->height/2); diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 3610e54c7..ef32b56a6 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -644,6 +644,7 @@ static int libd_drawStretched(lua_State *L) } // KART: draw patch on minimap from x, y coordinates on the map +// Sal: Let's please just merge the relevant info into the actual function, and have Lua call that... static int libd_drawOnMinimap(lua_State *L) { fixed_t x, y, scale; // coordinates of the object @@ -652,7 +653,7 @@ static int libd_drawOnMinimap(lua_State *L) boolean centered; // the patch is centered and doesn't need readjusting on x/y coordinates. // variables used to replicate k_kart's mmap drawer: - INT32 lumpnum = LUMPERROR; + lumpnum_t lumpnum = LUMPERROR; patch_t *AutomapPic; INT32 mx, my; INT32 splitflags, minimaptrans; @@ -743,10 +744,12 @@ static int libd_drawOnMinimap(lua_State *L) lumpnum = W_CheckNumForLongName(mapheaderinfo[gamemap-1]->minimapLump); } - if (lumpnum != -1) - AutomapPic = W_CachePatchNum(lumpnum, PU_HUDGFX); - else + if (lumpnum == LUMPERROR) + { return 0; // no pic, just get outta here + } + + AutomapPic = W_CachePatchNum(lumpnum, PU_HUDGFX); mx = MM_X - (AutomapPic->width/2); my = MM_Y - (AutomapPic->height/2); diff --git a/src/m_menu.c b/src/m_menu.c index 4c1eca56b..434efea54 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -5527,9 +5527,9 @@ static void DrawReplayHutReplayInfo(void) // A 160x100 image of the level as entry MAPxxP //CONS_Printf("%d %s\n", demolist[dir_on[menudepthleft]].map, G_BuildMapName(demolist[dir_on[menudepthleft]].map)); - if (mapheaderinfo[demolist[dir_on[menudepthleft]].map]) + if (mapheaderinfo[demolist[dir_on[menudepthleft]].map - 1]) { - lumpnum = W_CheckNumForLongName(mapheaderinfo[demolist[dir_on[menudepthleft]].map]->thumbnailLump); + lumpnum = W_CheckNumForLongName(mapheaderinfo[demolist[dir_on[menudepthleft]].map - 1]->thumbnailLump); } if (lumpnum != LUMPERROR) @@ -8882,16 +8882,17 @@ static void M_StartServer(INT32 choice) static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) { - lumpnum_t lumpnum = LUMPERROR; + lumpnum_t lumpnum; patch_t *PictureOfLevel; INT32 x, y, w, i, oldval, trans, dupadjust = ((vid.width/vid.dupx) - BASEVIDWIDTH)>>1; // A 160x100 image of the level as entry MAPxxP if (cv_nextmap.value) { - if (mapheaderinfo[cv_nextmap.value]) + lumpnum = LUMPERROR; + if (mapheaderinfo[cv_nextmap.value-1]) { - lumpnum = W_CheckNumForLongName(mapheaderinfo[cv_nextmap.value]->thumbnailLump); + lumpnum = W_CheckNumForLongName(mapheaderinfo[cv_nextmap.value-1]->thumbnailLump); } if (lumpnum != LUMPERROR) @@ -8959,9 +8960,10 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) // A 160x100 image of the level as entry MAPxxP if (i+1) { - if (mapheaderinfo[i+1]) + lumpnum = LUMPERROR; + if (mapheaderinfo[i]) { - lumpnum = W_CheckNumForLongName(mapheaderinfo[i+1]->thumbnailLump); + lumpnum = W_CheckNumForLongName(mapheaderinfo[i]->thumbnailLump); } if (lumpnum != LUMPERROR) @@ -9001,9 +9003,10 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) // A 160x100 image of the level as entry MAPxxP if (i+1) { - if (mapheaderinfo[i+1]) + lumpnum = LUMPERROR; + if (mapheaderinfo[i]) { - lumpnum = W_CheckNumForLongName(mapheaderinfo[i+1]->thumbnailLump); + lumpnum = W_CheckNumForLongName(mapheaderinfo[i]->thumbnailLump); } if (lumpnum != LUMPERROR) diff --git a/src/w_wad.c b/src/w_wad.c index 1b79b0a45..e7fa8c668 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1135,6 +1135,9 @@ lumpnum_t W_CheckNumForName(const char *name) INT32 i; lumpnum_t check = INT16_MAX; + if (name == NULL) + return LUMPERROR; + if (!*name) // some doofus gave us an empty string? return LUMPERROR; @@ -1182,6 +1185,9 @@ lumpnum_t W_CheckNumForLongName(const char *name) INT32 i; lumpnum_t check = INT16_MAX; + if (name == NULL) + return LUMPERROR; + if (!*name) // some doofus gave us an empty string? return LUMPERROR; diff --git a/src/y_inter.c b/src/y_inter.c index 6174bf86d..c6a2edfe2 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -1790,7 +1790,7 @@ void Y_StartVote(void) // set up the pic if (mapheaderinfo[votelevels[i][0]+1]) { - lumpnum = W_CheckNumForLongName(mapheaderinfo[votelevels[i][0]+1]->thumbnailLump); + lumpnum = W_CheckNumForLongName(mapheaderinfo[votelevels[i][0]]->thumbnailLump); } if (lumpnum != LUMPERROR)