From 212358dbba7f2e5e47ac12c3a3d6f705ba027d60 Mon Sep 17 00:00:00 2001 From: Louis-Antoine Date: Sun, 26 Apr 2020 00:39:52 +0200 Subject: [PATCH 1/3] Restore old entry searching functions and add alternate versions for long names --- src/lua_hudlib.c | 6 +-- src/w_wad.c | 120 +++++++++++++++++++++++++++++++++++++++++++++-- src/w_wad.h | 4 ++ 3 files changed, 124 insertions(+), 6 deletions(-) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 818e760c9..703b924bb 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -412,9 +412,9 @@ static int libd_cachePatch(lua_State *L) HUDONLY luapat = patchinfohead; - lumpnum = W_CheckNumForName(luaL_checkstring(L, 1)); + lumpnum = W_CheckNumForLongName(luaL_checkstring(L, 1)); if (lumpnum == LUMPERROR) - lumpnum = W_GetNumForName("MISSING"); + lumpnum = W_GetNumForLongName("MISSING"); for (i = 0; i < numluapatches; i++) { @@ -454,7 +454,7 @@ static int libd_cachePatch(lua_State *L) numluapatches++; #else HUDONLY - LUA_PushUserdata(L, W_CachePatchName(luaL_checkstring(L, 1), PU_PATCH), META_PATCH); + LUA_PushUserdata(L, W_CachePatchLongName(luaL_checkstring(L, 1), PU_PATCH), META_PATCH); #endif return 1; } diff --git a/src/w_wad.c b/src/w_wad.c index f273753c8..a81132354 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -920,6 +920,40 @@ const char *W_CheckNameForNum(lumpnum_t lumpnum) // 'startlump' is the lump number to start the search // UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump) +{ + UINT16 i; + static char uname[8 + 1]; + + if (!TestValidLump(wad,0)) + return INT16_MAX; + + strlcpy(uname, name, sizeof uname); + strupr(uname); + + // + // scan forward + // start at 'startlump', useful parameter when there are multiple + // resources with the same name + // + if (startlump < wadfiles[wad]->numlumps) + { + lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump; + for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++) + if (!strncmp(lump_p->name, uname, sizeof(uname) - 1)) + return i; + } + + // not found. + return INT16_MAX; +} + +// +// Like W_CheckNumForNamePwad, but can find entries with long names +// +// 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 i; static char uname[256 + 1]; @@ -1025,7 +1059,8 @@ lumpnum_t W_CheckNumForName(const char *name) // most recent entries first for (i = lumpnumcacheindex + LUMPNUMCACHESIZE; i > lumpnumcacheindex; i--) { - if (strcmp(lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname, name) == 0) + if (!lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname[8] + && strncmp(lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname, name, 8) == 0) { lumpnumcacheindex = i & (LUMPNUMCACHESIZE - 1); return lumpnumcache[lumpnumcacheindex].lumpnum; @@ -1045,13 +1080,63 @@ lumpnum_t W_CheckNumForName(const char *name) { // Update the cache. lumpnumcacheindex = (lumpnumcacheindex + 1) & (LUMPNUMCACHESIZE - 1); - strlcpy(lumpnumcache[lumpnumcacheindex].lumpname, name, 32); + memset(lumpnumcache[lumpnumcacheindex].lumpname, '\0', 32); + strncpy(lumpnumcache[lumpnumcacheindex].lumpname, name, 8); lumpnumcache[lumpnumcacheindex].lumpnum = (i<<16)+check; return lumpnumcache[lumpnumcacheindex].lumpnum; } } +// +// Like W_CheckNumForName, but can find entries with long names +// +// 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) +{ + INT32 i; + lumpnum_t check = INT16_MAX; + + if (!*name) // some doofus gave us an empty string? + return LUMPERROR; + + // Check the lumpnumcache first. Loop backwards so that we check + // most recent entries first + for (i = lumpnumcacheindex + LUMPNUMCACHESIZE; i > lumpnumcacheindex; i--) + { + if (strcmp(lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname, name) == 0) + { + lumpnumcacheindex = i & (LUMPNUMCACHESIZE - 1); + return lumpnumcache[lumpnumcacheindex].lumpnum; + } + } + + // scan wad files backwards so patch lump files take precedence + for (i = numwadfiles - 1; i >= 0; i--) + { + check = W_CheckNumForLongNamePwad(name,(UINT16)i,0); + if (check != INT16_MAX) + break; //found it + } + + if (check == INT16_MAX) return LUMPERROR; + else + { + if (strlen(name) < 32) + { + // Update the cache. + lumpnumcacheindex = (lumpnumcacheindex + 1) & (LUMPNUMCACHESIZE - 1); + memset(lumpnumcache[lumpnumcacheindex].lumpname, '\0', 32); + strlcpy(lumpnumcache[lumpnumcacheindex].lumpname, name, 32); + lumpnumcache[lumpnumcacheindex].lumpnum = (i << 16) + check; + } + + return (i << 16) + check; + } +} + // Look for valid map data through all added files in descendant order. // Get a map marker for WADs, and a standalone WAD file lump inside PK3s. // TODO: Make it search through cache first, maybe...? @@ -1100,6 +1185,24 @@ lumpnum_t W_GetNumForName(const char *name) return i; } +// +// Like W_GetNumForName, but can find entries with long names +// +// 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 i; + + i = W_CheckNumForLongName(name); + + if (i == LUMPERROR) + I_Error("W_GetNumForLongName: %s not found!\n", name); + + return i; +} + // // W_CheckNumForNameInBlock // Checks only in blocks from blockstart lump to blockend lump @@ -1139,7 +1242,7 @@ UINT8 W_LumpExists(const char *name) { lumpinfo_t *lump_p = wadfiles[i]->lumpinfo; for (j = 0; j < wadfiles[i]->numlumps; ++j, ++lump_p) - if (fastcmp(lump_p->name,name)) + if (fastcmp(lump_p->longname, name)) return true; } return false; @@ -1680,6 +1783,17 @@ void *W_CachePatchName(const char *name, INT32 tag) return W_CachePatchNum(W_GetNumForName("MISSING"), tag); return W_CachePatchNum(num, tag); } + +void *W_CachePatchLongName(const char *name, INT32 tag) +{ + lumpnum_t num; + + num = W_CheckNumForLongName(name); + + if (num == LUMPERROR) + return W_CachePatchNum(W_GetNumForLongName("MISSING"), tag); + return W_CachePatchNum(num, tag); +} #ifndef NOMD5 #define MD5_LEN 16 diff --git a/src/w_wad.h b/src/w_wad.h index 3af6148f4..88b542fca 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -156,6 +156,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); /* Find the first lump after F_START for instance. */ UINT16 W_CheckNumForMarkerStartPwad(const char *name, UINT16 wad, UINT16 startlump); @@ -166,7 +167,9 @@ UINT16 W_CheckNumForFolderEndPK3(const char *name, UINT16 wad, UINT16 startlump) lumpnum_t W_CheckNumForMap(const char *name); lumpnum_t W_CheckNumForName(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_CheckNumForNameInBlock(const char *name, const char *blockstart, const char *blockend); UINT8 W_LumpExists(const char *name); // Lua uses this. @@ -194,6 +197,7 @@ boolean W_IsPatchCached(lumpnum_t lump, void *ptr); void *W_CacheLumpName(const char *name, INT32 tag); void *W_CachePatchName(const char *name, INT32 tag); +void *W_CachePatchLongName(const char *name, INT32 tag); // Returns either a Software patch, or an OpenGL patch. // Performs any necessary conversions from PNG images. From 2e27f32d3e3c7de727867fa0c25f75f0c9ebe698 Mon Sep 17 00:00:00 2001 From: Louis-Antoine Date: Sun, 26 Apr 2020 00:42:17 +0200 Subject: [PATCH 2/3] Replace a few instance of strncpy with strlcpy --- src/dehacked.c | 6 ++---- src/f_finale.c | 4 ++-- src/m_menu.c | 14 +++++++------- src/m_menu.h | 2 +- src/p_setup.c | 4 +--- src/r_data.c | 5 ++--- src/v_video.c | 2 +- src/w_wad.c | 8 +++----- src/y_inter.c | 5 ++--- 9 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index e9d029be0..fbd42dee1 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -419,7 +419,7 @@ static void readPlayer(MYFILE *f, INT32 num) if (fastcmp(word, "PICNAME")) { SLOTFOUND - strncpy(description[num].picname, word2, 8); + strlcpy(description[num].picname, word2, sizeof(description->picname)); } // new character select else if (fastcmp(word, "DISPLAYNAME")) @@ -3889,9 +3889,7 @@ static void readmaincfg(MYFILE *f) lumpnum_t lumpnum; char newname[9]; - strncpy(newname, word2, 8); - - newname[8] = '\0'; + strlcpy(newname, word2, sizeof(newname)); lumpnum = W_CheckNumForName(newname); diff --git a/src/f_finale.c b/src/f_finale.c index 825f646b0..abef1da69 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -2338,7 +2338,7 @@ void F_InitMenuPresValues(void) activeMenuId = MainDef.menuid; // Set defaults for presentation values - strncpy(curbgname, "TITLESKY", 9); + strlcpy(curbgname, "TITLESKY", sizeof(curbgname)); curfadevalue = 16; curbgcolor = -1; curbgxspeed = (gamestate == GS_TIMEATTACK) ? 0 : titlescrollxspeed; @@ -2348,7 +2348,7 @@ void F_InitMenuPresValues(void) curhidepics = hidetitlepics; curttmode = ttmode; curttscale = ttscale; - strncpy(curttname, ttname, 9); + strlcpy(curttname, ttname, sizeof(curttname)); curttx = ttx; curtty = tty; curttloop = ttloop; diff --git a/src/m_menu.c b/src/m_menu.c index 1069f0f30..e510f582a 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2615,7 +2615,7 @@ static boolean MIT_SetCurBackground(UINT32 menutype, INT32 level, INT32 *retval, } else if (menupres[menutype].bgname[0]) { - strncpy(curbgname, menupres[menutype].bgname, 8); + strlcpy(curbgname, menupres[menutype].bgname, sizeof(curbgname)); curbgxspeed = menupres[menutype].titlescrollxspeed != INT32_MAX ? menupres[menutype].titlescrollxspeed : titlescrollxspeed; curbgyspeed = menupres[menutype].titlescrollyspeed != INT32_MAX ? menupres[menutype].titlescrollyspeed : titlescrollyspeed; return true; @@ -2628,7 +2628,7 @@ static boolean MIT_SetCurBackground(UINT32 menutype, INT32 level, INT32 *retval, curbghide = true; else { - strncpy(curbgname, defaultname, 9); + strlcpy(curbgname, defaultname, sizeof(curbgname)); curbgxspeed = (gamestate == GS_TIMEATTACK) ? 0 : titlescrollxspeed; curbgyspeed = (gamestate == GS_TIMEATTACK) ? 0 : titlescrollyspeed; } @@ -2767,7 +2767,7 @@ void M_ChangeMenuMusic(const char *defaultmusname, boolean defaultmuslooping) void M_SetMenuCurBackground(const char *defaultname) { char name[9]; - strncpy(name, defaultname, 8); + strlcpy(name, defaultname, 9); M_IterateMenuTree(MIT_SetCurBackground, &name); } @@ -2820,7 +2820,7 @@ static void M_HandleMenuPresState(menu_t *newMenu) activeMenuId = newMenu ? newMenu->menuid : 0; // Set defaults for presentation values - strncpy(curbgname, "TITLESKY", 9); + strlcpy(curbgname, "TITLESKY", sizeof(curbgname)); curfadevalue = 16; curhidepics = hidetitlepics; curbgcolor = -1; @@ -5785,7 +5785,7 @@ static void M_DrawLevelPlatterMenu(void) { F_SkyScroll(curbgxspeed, curbgyspeed, curbgname); // Draw and animate foreground - if (!strncmp("RECATKBG", curbgname, 8)) + if (!strcmp("RECATKBG", curbgname)) M_DrawRecordAttackForeground(); } @@ -6033,7 +6033,7 @@ static void M_DrawMessageMenu(void) else { F_SkyScroll(curbgxspeed, curbgyspeed, curbgname); - if (!strncmp("RECATKBG", curbgname, 8)) + if (!strcmp("RECATKBG", curbgname)) M_DrawRecordAttackForeground(); } } @@ -9583,7 +9583,7 @@ void M_DrawTimeAttackMenu(void) { F_SkyScroll(curbgxspeed, curbgyspeed, curbgname); // Draw and animate foreground - if (!strncmp("RECATKBG", curbgname, 8)) + if (!strcmp("RECATKBG", curbgname)) M_DrawRecordAttackForeground(); } if (curfadevalue) diff --git a/src/m_menu.h b/src/m_menu.h index eeda9cc58..0658f38da 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -340,7 +340,7 @@ typedef struct { boolean used; char notes[441]; - char picname[8]; + char picname[9]; char skinname[SKINNAMESIZE*2+2]; // skin&skin\0 patch_t *charpic; UINT8 prev; diff --git a/src/p_setup.c b/src/p_setup.c index 8c73b85e6..61a49d958 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2883,9 +2883,7 @@ static void P_RunLevelScript(const char *scriptname) lumpnum_t lumpnum; char newname[9]; - strncpy(newname, scriptname, 8); - - newname[8] = '\0'; + strlcpy(newname, scriptname, sizeof(newname)); lumpnum = W_CheckNumForName(newname); diff --git a/src/r_data.c b/src/r_data.c index 831e75bef..c542bbd98 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -2603,7 +2603,7 @@ INT32 R_CheckTextureNumForName(const char *name) return 0; for (i = 0; i < tidcachelen; i++) - if (!strncasecmp(tidcache[i].name, name, 8)) + if (!strcasecmp(tidcache[i].name, name)) return tidcache[i].id; // Need to parse the list backwards, so textures loaded more recently are used in lieu of ones loaded earlier @@ -2613,8 +2613,7 @@ INT32 R_CheckTextureNumForName(const char *name) { tidcachelen++; Z_Realloc(tidcache, tidcachelen * sizeof(*tidcache), PU_STATIC, &tidcache); - strncpy(tidcache[tidcachelen-1].name, name, 8); - tidcache[tidcachelen-1].name[8] = '\0'; + strlcpy(tidcache[tidcachelen-1].name, name, sizeof(tidcache->name)); #ifndef ZDEBUG CONS_Debug(DBG_SETUP, "texture #%s: %s\n", sizeu1(tidcachelen), tidcache[tidcachelen-1].name); #endif diff --git a/src/v_video.c b/src/v_video.c index 2d1014c23..e03d0a60d 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -391,7 +391,7 @@ const char *R_GetPalname(UINT16 num) if (num > 0 && num <= 10000) snprintf(newpal, 8, "PAL%04u", num-1); - strncpy(palname, newpal, 8); + strlcpy(palname, newpal, sizeof(palname)); return palname; } diff --git a/src/w_wad.c b/src/w_wad.c index a81132354..267f06198 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -440,17 +440,15 @@ static lumpinfo_t* ResGetLumpsWad (FILE* handle, UINT16* nlmp, const char* filen else lump_p->compression = CM_NOCOMPRESSION; memset(lump_p->name, 0x00, 9); - strncpy(lump_p->name, fileinfo->name, 8); + strlcpy(lump_p->name, fileinfo->name, 9); // Allocate the lump's long name. lump_p->longname = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL); - strncpy(lump_p->longname, fileinfo->name, 8); - lump_p->longname[8] = '\0'; + strlcpy(lump_p->longname, fileinfo->name, 9); // Allocate the lump's full name. lump_p->fullname = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL); - strncpy(lump_p->fullname, fileinfo->name, 8); - lump_p->fullname[8] = '\0'; + strlcpy(lump_p->fullname, fileinfo->name, 9); } free(fileinfov); *nlmp = numlumps; diff --git a/src/y_inter.c b/src/y_inter.c index f1764a816..ce57bef9e 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -1740,9 +1740,8 @@ static void Y_CalculateCompetitionWinners(void) data.competition.monitors[data.competition.numplayers] = monitors[winner]; data.competition.scores[data.competition.numplayers] = scores[winner]; - strncpy(tempname, player_names[winner], 8); - tempname[8] = '\0'; - strncpy(data.competition.name[data.competition.numplayers], tempname, 9); + strlcpy(tempname, player_names[winner], 9); + strlcpy(data.competition.name[data.competition.numplayers], tempname, 9); data.competition.color[data.competition.numplayers] = &players[winner].skincolor; data.competition.character[data.competition.numplayers] = &players[winner].skin; From 9b3917cd729895c0f0e2db8792d3b721222afef4 Mon Sep 17 00:00:00 2001 From: Louis-Antoine Date: Wed, 29 Apr 2020 10:55:49 +0200 Subject: [PATCH 3/3] Revert "Replace a few instance of strncpy with strlcpy" This reverts commit 2e27f32d3e3c7de727867fa0c25f75f0c9ebe698. --- src/dehacked.c | 6 ++++-- src/f_finale.c | 4 ++-- src/m_menu.c | 14 +++++++------- src/m_menu.h | 2 +- src/p_setup.c | 4 +++- src/r_data.c | 5 +++-- src/v_video.c | 2 +- src/w_wad.c | 8 +++++--- src/y_inter.c | 5 +++-- 9 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index fbd42dee1..e9d029be0 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -419,7 +419,7 @@ static void readPlayer(MYFILE *f, INT32 num) if (fastcmp(word, "PICNAME")) { SLOTFOUND - strlcpy(description[num].picname, word2, sizeof(description->picname)); + strncpy(description[num].picname, word2, 8); } // new character select else if (fastcmp(word, "DISPLAYNAME")) @@ -3889,7 +3889,9 @@ static void readmaincfg(MYFILE *f) lumpnum_t lumpnum; char newname[9]; - strlcpy(newname, word2, sizeof(newname)); + strncpy(newname, word2, 8); + + newname[8] = '\0'; lumpnum = W_CheckNumForName(newname); diff --git a/src/f_finale.c b/src/f_finale.c index abef1da69..825f646b0 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -2338,7 +2338,7 @@ void F_InitMenuPresValues(void) activeMenuId = MainDef.menuid; // Set defaults for presentation values - strlcpy(curbgname, "TITLESKY", sizeof(curbgname)); + strncpy(curbgname, "TITLESKY", 9); curfadevalue = 16; curbgcolor = -1; curbgxspeed = (gamestate == GS_TIMEATTACK) ? 0 : titlescrollxspeed; @@ -2348,7 +2348,7 @@ void F_InitMenuPresValues(void) curhidepics = hidetitlepics; curttmode = ttmode; curttscale = ttscale; - strlcpy(curttname, ttname, sizeof(curttname)); + strncpy(curttname, ttname, 9); curttx = ttx; curtty = tty; curttloop = ttloop; diff --git a/src/m_menu.c b/src/m_menu.c index e510f582a..1069f0f30 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2615,7 +2615,7 @@ static boolean MIT_SetCurBackground(UINT32 menutype, INT32 level, INT32 *retval, } else if (menupres[menutype].bgname[0]) { - strlcpy(curbgname, menupres[menutype].bgname, sizeof(curbgname)); + strncpy(curbgname, menupres[menutype].bgname, 8); curbgxspeed = menupres[menutype].titlescrollxspeed != INT32_MAX ? menupres[menutype].titlescrollxspeed : titlescrollxspeed; curbgyspeed = menupres[menutype].titlescrollyspeed != INT32_MAX ? menupres[menutype].titlescrollyspeed : titlescrollyspeed; return true; @@ -2628,7 +2628,7 @@ static boolean MIT_SetCurBackground(UINT32 menutype, INT32 level, INT32 *retval, curbghide = true; else { - strlcpy(curbgname, defaultname, sizeof(curbgname)); + strncpy(curbgname, defaultname, 9); curbgxspeed = (gamestate == GS_TIMEATTACK) ? 0 : titlescrollxspeed; curbgyspeed = (gamestate == GS_TIMEATTACK) ? 0 : titlescrollyspeed; } @@ -2767,7 +2767,7 @@ void M_ChangeMenuMusic(const char *defaultmusname, boolean defaultmuslooping) void M_SetMenuCurBackground(const char *defaultname) { char name[9]; - strlcpy(name, defaultname, 9); + strncpy(name, defaultname, 8); M_IterateMenuTree(MIT_SetCurBackground, &name); } @@ -2820,7 +2820,7 @@ static void M_HandleMenuPresState(menu_t *newMenu) activeMenuId = newMenu ? newMenu->menuid : 0; // Set defaults for presentation values - strlcpy(curbgname, "TITLESKY", sizeof(curbgname)); + strncpy(curbgname, "TITLESKY", 9); curfadevalue = 16; curhidepics = hidetitlepics; curbgcolor = -1; @@ -5785,7 +5785,7 @@ static void M_DrawLevelPlatterMenu(void) { F_SkyScroll(curbgxspeed, curbgyspeed, curbgname); // Draw and animate foreground - if (!strcmp("RECATKBG", curbgname)) + if (!strncmp("RECATKBG", curbgname, 8)) M_DrawRecordAttackForeground(); } @@ -6033,7 +6033,7 @@ static void M_DrawMessageMenu(void) else { F_SkyScroll(curbgxspeed, curbgyspeed, curbgname); - if (!strcmp("RECATKBG", curbgname)) + if (!strncmp("RECATKBG", curbgname, 8)) M_DrawRecordAttackForeground(); } } @@ -9583,7 +9583,7 @@ void M_DrawTimeAttackMenu(void) { F_SkyScroll(curbgxspeed, curbgyspeed, curbgname); // Draw and animate foreground - if (!strcmp("RECATKBG", curbgname)) + if (!strncmp("RECATKBG", curbgname, 8)) M_DrawRecordAttackForeground(); } if (curfadevalue) diff --git a/src/m_menu.h b/src/m_menu.h index 0658f38da..eeda9cc58 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -340,7 +340,7 @@ typedef struct { boolean used; char notes[441]; - char picname[9]; + char picname[8]; char skinname[SKINNAMESIZE*2+2]; // skin&skin\0 patch_t *charpic; UINT8 prev; diff --git a/src/p_setup.c b/src/p_setup.c index 61a49d958..8c73b85e6 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2883,7 +2883,9 @@ static void P_RunLevelScript(const char *scriptname) lumpnum_t lumpnum; char newname[9]; - strlcpy(newname, scriptname, sizeof(newname)); + strncpy(newname, scriptname, 8); + + newname[8] = '\0'; lumpnum = W_CheckNumForName(newname); diff --git a/src/r_data.c b/src/r_data.c index c542bbd98..831e75bef 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -2603,7 +2603,7 @@ INT32 R_CheckTextureNumForName(const char *name) return 0; for (i = 0; i < tidcachelen; i++) - if (!strcasecmp(tidcache[i].name, name)) + if (!strncasecmp(tidcache[i].name, name, 8)) return tidcache[i].id; // Need to parse the list backwards, so textures loaded more recently are used in lieu of ones loaded earlier @@ -2613,7 +2613,8 @@ INT32 R_CheckTextureNumForName(const char *name) { tidcachelen++; Z_Realloc(tidcache, tidcachelen * sizeof(*tidcache), PU_STATIC, &tidcache); - strlcpy(tidcache[tidcachelen-1].name, name, sizeof(tidcache->name)); + strncpy(tidcache[tidcachelen-1].name, name, 8); + tidcache[tidcachelen-1].name[8] = '\0'; #ifndef ZDEBUG CONS_Debug(DBG_SETUP, "texture #%s: %s\n", sizeu1(tidcachelen), tidcache[tidcachelen-1].name); #endif diff --git a/src/v_video.c b/src/v_video.c index e03d0a60d..2d1014c23 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -391,7 +391,7 @@ const char *R_GetPalname(UINT16 num) if (num > 0 && num <= 10000) snprintf(newpal, 8, "PAL%04u", num-1); - strlcpy(palname, newpal, sizeof(palname)); + strncpy(palname, newpal, 8); return palname; } diff --git a/src/w_wad.c b/src/w_wad.c index 267f06198..a81132354 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -440,15 +440,17 @@ static lumpinfo_t* ResGetLumpsWad (FILE* handle, UINT16* nlmp, const char* filen else lump_p->compression = CM_NOCOMPRESSION; memset(lump_p->name, 0x00, 9); - strlcpy(lump_p->name, fileinfo->name, 9); + strncpy(lump_p->name, fileinfo->name, 8); // Allocate the lump's long name. lump_p->longname = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL); - strlcpy(lump_p->longname, fileinfo->name, 9); + strncpy(lump_p->longname, fileinfo->name, 8); + lump_p->longname[8] = '\0'; // Allocate the lump's full name. lump_p->fullname = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL); - strlcpy(lump_p->fullname, fileinfo->name, 9); + strncpy(lump_p->fullname, fileinfo->name, 8); + lump_p->fullname[8] = '\0'; } free(fileinfov); *nlmp = numlumps; diff --git a/src/y_inter.c b/src/y_inter.c index ce57bef9e..f1764a816 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -1740,8 +1740,9 @@ static void Y_CalculateCompetitionWinners(void) data.competition.monitors[data.competition.numplayers] = monitors[winner]; data.competition.scores[data.competition.numplayers] = scores[winner]; - strlcpy(tempname, player_names[winner], 9); - strlcpy(data.competition.name[data.competition.numplayers], tempname, 9); + strncpy(tempname, player_names[winner], 8); + tempname[8] = '\0'; + strncpy(data.competition.name[data.competition.numplayers], tempname, 9); data.competition.color[data.competition.numplayers] = &players[winner].skincolor; data.competition.character[data.competition.numplayers] = &players[winner].skin;