Commit 2e27f32d by LJ Sonic

Replace a few instance of strncpy with strlcpy

parent 212358db
......@@ -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);
......
......@@ -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;
......
......@@ -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)
......
......@@ -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;
......
......@@ -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);
......
......@@ -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
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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;
......
  • mentioned in commit 9b3917cd

    Toggle commit list
  • Turns out that second commit caused weird slowdowns at level load, so I reverted it. It did not contain important changes anyway.

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment