Clean up stringop-truncation warnings

This commit is contained in:
Alam Ed Arias 2024-02-20 16:30:15 -05:00
parent 53d74e7f89
commit 703ee972e6
16 changed files with 91 additions and 86 deletions

View file

@ -310,9 +310,7 @@ target_compile_options(SRB2SDL2 PRIVATE
$<$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,8.1.0>: $<$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,8.1.0>:
-Wno-error=format-overflow -Wno-error=format-overflow
-Wno-error=stringop-truncation
-Wno-format-overflow -Wno-format-overflow
-Wno-stringop-truncation
-Wno-error=multistatement-macros -Wno-error=multistatement-macros
> >

View file

@ -135,9 +135,7 @@ ifdef GCC71
endif endif
ifdef GCC81 ifdef GCC81
WFLAGS+=-Wno-error=format-overflow WFLAGS+=-Wno-error=format-overflow
WFLAGS+=-Wno-error=stringop-truncation
WFLAGS+=-Wno-format-overflow WFLAGS+=-Wno-format-overflow
WFLAGS+=-Wno-stringop-truncation
WFLAGS+=-Wno-error=multistatement-macros WFLAGS+=-Wno-error=multistatement-macros
endif endif

View file

@ -2060,16 +2060,16 @@ void CV_StealthSet(consvar_t *var, const char *value)
*/ */
static void CV_SetValueMaybeStealth(consvar_t *var, INT32 value, boolean stealth) static void CV_SetValueMaybeStealth(consvar_t *var, INT32 value, boolean stealth)
{ {
char val[SKINNAMESIZE+1]; char val[SKINNAMESIZE+1] = "None";
if (var == &cv_forceskin) // Special handling. if (var == &cv_forceskin) // Special handling.
{ {
const char *tmpskin = NULL; const char *tmpskin = NULL;
if ((value < 0) || (value >= numskins)) if ((value < 0) || (value >= numskins))
tmpskin = "None"; ;
else else
tmpskin = skins[value]->name; tmpskin = skins[value]->name;
strncpy(val, tmpskin, SKINNAMESIZE); memcpy(val, tmpskin, SKINNAMESIZE);
} }
else else
sprintf(val, "%d", value); sprintf(val, "%d", value);

View file

@ -324,7 +324,7 @@ void readPlayer(MYFILE *f, INT32 num)
if (fastcmp(word, "PICNAME")) if (fastcmp(word, "PICNAME"))
{ {
SLOTFOUND SLOTFOUND
strncpy(description[num].picname, word2, 8); strncpy(description[num].picname, word2, sizeof(description[num].picname)-1);
} }
else if (fastcmp(word, "DISPLAYNAME")) else if (fastcmp(word, "DISPLAYNAME"))
{ {
@ -355,7 +355,7 @@ void readPlayer(MYFILE *f, INT32 num)
else if (fastcmp(word, "NAMETAG") || fastcmp(word, "TAGNAME")) else if (fastcmp(word, "NAMETAG") || fastcmp(word, "TAGNAME"))
{ {
SLOTFOUND SLOTFOUND
strncpy(description[num].nametag, word2, 8); strncpy(description[num].nametag, word2, sizeof(description[num].nametag)-1);
} }
else if (fastcmp(word, "TAGTEXTCOLOR") || fastcmp(word, "TAGTEXTCOLOUR")) else if (fastcmp(word, "TAGTEXTCOLOR") || fastcmp(word, "TAGTEXTCOLOUR"))
{ {
@ -1163,7 +1163,7 @@ void readgametype(MYFILE *f, char *gtname)
INT16 newgtrankingstype = -1; INT16 newgtrankingstype = -1;
int newgtinttype = 0; int newgtinttype = 0;
char gtdescription[441]; char gtdescription[441];
char gtconst[MAXLINELEN]; char gtconst[MAXLINELEN+1];
// Empty strings. // Empty strings.
gtdescription[0] = '\0'; gtdescription[0] = '\0';
@ -1677,7 +1677,7 @@ void readlevelheader(MYFILE *f, INT32 num)
else if (fastcmp(word, "SKYNUM")) else if (fastcmp(word, "SKYNUM"))
mapheaderinfo[num-1]->skynum = (INT16)i; mapheaderinfo[num-1]->skynum = (INT16)i;
else if (fastcmp(word, "INTERSCREEN")) else if (fastcmp(word, "INTERSCREEN"))
strncpy(mapheaderinfo[num-1]->interscreen, word2, 8); strncpy(mapheaderinfo[num-1]->interscreen, word2, sizeof(mapheaderinfo[num-1]->interscreen)-1);
else if (fastcmp(word, "PRECUTSCENENUM")) else if (fastcmp(word, "PRECUTSCENENUM"))
mapheaderinfo[num-1]->precutscenenum = (UINT8)i; mapheaderinfo[num-1]->precutscenenum = (UINT8)i;
else if (fastcmp(word, "CUTSCENENUM")) else if (fastcmp(word, "CUTSCENENUM"))
@ -2294,7 +2294,7 @@ static void readtextpromptpage(MYFILE *f, INT32 num, INT32 pagenum)
char name[34]; char name[34];
name[0] = '\x82'; // color yellow name[0] = '\x82'; // color yellow
name[1] = 0; name[1] = 0;
strncat(name, word2, 33); strncat(name, word2, 32);
name[33] = 0; name[33] = 0;
// Replace _ with ' ' // Replace _ with ' '
@ -2304,7 +2304,7 @@ static void readtextpromptpage(MYFILE *f, INT32 num, INT32 pagenum)
name[j] = ' '; name[j] = ' ';
} }
strncpy(textprompts[num]->page[pagenum].name, name, 32); strncpy(textprompts[num]->page[pagenum].name, name, sizeof(textprompts[num]->page[pagenum].name));
} }
else else
*textprompts[num]->page[pagenum].name = '\0'; *textprompts[num]->page[pagenum].name = '\0';
@ -3794,7 +3794,7 @@ void readmaincfg(MYFILE *f)
} }
else if (fastcmp(word, "TITLEPICSNAME")) else if (fastcmp(word, "TITLEPICSNAME"))
{ {
strncpy(ttname, word2, 9); strncpy(ttname, word2, sizeof(ttname)-1);
titlechanged = true; titlechanged = true;
} }
else if (fastcmp(word, "TITLEPICSX")) else if (fastcmp(word, "TITLEPICSX"))
@ -3878,8 +3878,12 @@ void readmaincfg(MYFILE *f)
savemoddata = true; savemoddata = true;
// Also save a time attack folder // Also save a time attack folder
filenamelen = strlen(gamedatafilename)-4; // Strip off the extension filenamelen = strlen(gamedatafilename); // Strip off the extension
strncpy(timeattackfolder, gamedatafilename, min(filenamelen, sizeof (timeattackfolder))); if (filenamelen >= 4)
filenamelen -= 4;
if (filenamelen >= sizeof(timeattackfolder))
filenamelen = sizeof(timeattackfolder)-1;
strncpy(timeattackfolder, gamedatafilename, filenamelen);
timeattackfolder[min(filenamelen, sizeof (timeattackfolder) - 1)] = '\0'; timeattackfolder[min(filenamelen, sizeof (timeattackfolder) - 1)] = '\0';
strcpy(savegamename, timeattackfolder); strcpy(savegamename, timeattackfolder);

View file

@ -165,7 +165,7 @@ extern boolean exitfadestarted;
typedef struct typedef struct
{ {
UINT8 numpics; UINT8 numpics;
char picname[8][8]; char picname[8][8+1];
UINT8 pichires[8]; UINT8 pichires[8];
char *text; char *text;
UINT16 xcoord[8]; UINT16 xcoord[8];
@ -296,17 +296,17 @@ typedef struct
typedef struct typedef struct
{ {
// The original eight, plus one. // The original eight, plus one.
char lvlttl[22]; ///< Level name without "Zone". (21 character limit instead of 32, 21 characters can display on screen max anyway) char lvlttl[21+1]; ///< Level name without "Zone". (21 character limit instead of 32, 21 characters can display on screen max anyway)
char subttl[33]; ///< Subtitle for level char subttl[32+1]; ///< Subtitle for level
UINT8 actnum; ///< Act number or 0 for none. UINT8 actnum; ///< Act number or 0 for none.
UINT32 typeoflevel; ///< Combination of typeoflevel flags. UINT32 typeoflevel; ///< Combination of typeoflevel flags.
INT16 nextlevel; ///< Map number of next level, or 1100-1102 to end. INT16 nextlevel; ///< Map number of next level, or 1100-1102 to end.
INT16 marathonnext; ///< See nextlevel, but for Marathon mode. Necessary to support hub worlds ala SUGOI. INT16 marathonnext; ///< See nextlevel, but for Marathon mode. Necessary to support hub worlds ala SUGOI.
char keywords[33]; ///< Keywords separated by space to search for. 32 characters. char keywords[32+1]; ///< Keywords separated by space to search for. 32 characters.
char musname[7]; ///< Music track to play. "" for no music. char musname[7]; ///< Music track to play. "" for no music.
UINT16 mustrack; ///< Subsong to play. Only really relevant for music modules and specific formats supported by GME. 0 to ignore. UINT16 mustrack; ///< Subsong to play. Only really relevant for music modules and specific formats supported by GME. 0 to ignore.
UINT32 muspos; ///< Music position to jump to. UINT32 muspos; ///< Music position to jump to.
char forcecharacter[17]; ///< (SKINNAMESIZE+1) Skin to switch to or "" to disable. char forcecharacter[16+1]; ///< (SKINNAMESIZE+1) Skin to switch to or "" to disable.
UINT8 weather; ///< 0 = sunny day, 1 = storm, 2 = snow, 3 = rain, 4 = blank, 5 = thunder w/o rain, 6 = rain w/o lightning, 7 = heat wave. UINT8 weather; ///< 0 = sunny day, 1 = storm, 2 = snow, 3 = rain, 4 = blank, 5 = thunder w/o rain, 6 = rain w/o lightning, 7 = heat wave.
INT16 skynum; ///< Sky number to use. INT16 skynum; ///< Sky number to use.
INT16 skybox_scalex; ///< Skybox X axis scale. (0 = no movement, 1 = 1:1 movement, 16 = 16:1 slow movement, -4 = 1:4 fast movement, etc.) INT16 skybox_scalex; ///< Skybox X axis scale. (0 = no movement, 1 = 1:1 movement, 16 = 16:1 slow movement, -4 = 1:4 fast movement, etc.)
@ -314,9 +314,9 @@ typedef struct
INT16 skybox_scalez; ///< Skybox Z axis scale. INT16 skybox_scalez; ///< Skybox Z axis scale.
// Extra information. // Extra information.
char interscreen[8]; ///< 320x200 patch to display at intermission. char interscreen[8+1]; ///< 320x200 patch to display at intermission.
char runsoc[33]; ///< SOC to execute at start of level (32 character limit instead of 63) char runsoc[32+1]; ///< SOC to execute at start of level (32 character limit instead of 63)
char scriptname[33]; ///< Script to use when the map is switched to. (32 character limit instead of 191) char scriptname[32+1]; ///< Script to use when the map is switched to. (32 character limit instead of 191)
UINT8 precutscenenum; ///< Cutscene number to play BEFORE a level starts. UINT8 precutscenenum; ///< Cutscene number to play BEFORE a level starts.
UINT8 cutscenenum; ///< Cutscene number to use, 0 for none. UINT8 cutscenenum; ///< Cutscene number to use, 0 for none.
INT16 countdown; ///< Countdown until level end? INT16 countdown; ///< Countdown until level end?
@ -337,9 +337,9 @@ typedef struct
fixed_t gravity; ///< Map-wide gravity. fixed_t gravity; ///< Map-wide gravity.
// Title card. // Title card.
char ltzzpatch[9]; ///< Zig zag patch. char ltzzpatch[8+1]; ///< Zig zag patch.
char ltzztext[9]; ///< Zig zag text. char ltzztext[8+1]; ///< Zig zag text.
char ltactdiamond[9]; ///< Act diamond. char ltactdiamond[8+1]; ///< Act diamond.
// Freed animals stuff. // Freed animals stuff.
UINT8 numFlickies; ///< Internal. For freed flicky support. UINT8 numFlickies; ///< Internal. For freed flicky support.

View file

@ -96,7 +96,7 @@ typedef enum
extern ttmode_enum ttmode; extern ttmode_enum ttmode;
extern UINT8 ttscale; extern UINT8 ttscale;
// ttmode user vars // ttmode user vars
extern char ttname[9]; extern char ttname[8+1];
extern INT16 ttx; extern INT16 ttx;
extern INT16 tty; extern INT16 tty;
extern INT16 ttloop; extern INT16 ttloop;

View file

@ -496,10 +496,10 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags)
// what we're gonna do now is check if the player exists // what we're gonna do now is check if the player exists
// with that logic, characters 4 and 5 are our numbers: // with that logic, characters 4 and 5 are our numbers:
const char *newmsg; const char *newmsg;
char playernum[3]; char playernum[3+1];
INT32 spc = 1; // used if playernum[1] is a space. INT32 spc = 1; // used if playernum[1] is a space.
strncpy(playernum, msg+3, 3); strncpy(playernum, msg+3, sizeof(playernum)-1);
// check for undesirable characters in our "number" // check for undesirable characters in our "number"
if (((playernum[0] < '0') || (playernum[0] > '9')) || ((playernum[1] < '0') || (playernum[1] > '9'))) if (((playernum[0] < '0') || (playernum[0] > '9')) || ((playernum[1] < '0') || (playernum[1] > '9')))
{ {
@ -969,7 +969,7 @@ static void HU_sendChatMessage(void)
if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm
{ {
INT32 spc = 1; // used if playernum[1] is a space. INT32 spc = 1; // used if playernum[1] is a space.
char playernum[3]; char playernum[3+1];
const char *newmsg; const char *newmsg;
// what we're gonna do now is check if the player exists // what we're gonna do now is check if the player exists
@ -982,7 +982,7 @@ static void HU_sendChatMessage(void)
return; return;
} }
strncpy(playernum, msg+3, 3); strncpy(playernum, msg+3, sizeof(playernum)-1);
// check for undesirable characters in our "number" // check for undesirable characters in our "number"
if (!(isdigit(playernum[0]) && isdigit(playernum[1]))) if (!(isdigit(playernum[0]) && isdigit(playernum[1])))
{ {
@ -1679,13 +1679,14 @@ static void HU_DrawChat(void)
// filter: (code needs optimization pls help I'm bad with C) // filter: (code needs optimization pls help I'm bad with C)
if (w_chat[3]) if (w_chat[3])
{ {
char playernum[3]; char playernum[3+1];
UINT32 n; UINT32 n;
// right, that's half important: (w_chat[4] may be a space since /pm0 msg is perfectly acceptable!) // right, that's half important: (w_chat[4] may be a space since /pm0 msg is perfectly acceptable!)
if ( ( ((w_chat[3] != 0) && ((w_chat[3] < '0') || (w_chat[3] > '9'))) || ((w_chat[4] != 0) && (((w_chat[4] < '0') || (w_chat[4] > '9'))))) && (w_chat[4] != ' ')) if ( ( ((w_chat[3] != 0) && ((w_chat[3] < '0') || (w_chat[3] > '9'))) || ((w_chat[4] != 0) && (((w_chat[4] < '0') || (w_chat[4] > '9'))))) && (w_chat[4] != ' '))
break; break;
strncpy(playernum, w_chat+3, 3); strncpy(playernum, w_chat+3, sizeof(playernum)-1);
playernum[3] = 0;
n = atoi(playernum); // turn that into a number n = atoi(playernum); // turn that into a number
// special cases: // special cases:
@ -3052,7 +3053,7 @@ void HU_DoCEcho(const char *msg)
{ {
I_OutputMsg("%s\n", msg); // print to log I_OutputMsg("%s\n", msg); // print to log
strncpy(cechotext, msg, sizeof(cechotext)); strncpy(cechotext, msg, sizeof(cechotext)-1);
strncat(cechotext, "\\", sizeof(cechotext) - strlen(cechotext) - 1); strncat(cechotext, "\\", sizeof(cechotext) - strlen(cechotext) - 1);
cechotext[sizeof(cechotext) - 1] = '\0'; cechotext[sizeof(cechotext) - 1] = '\0';
cechotimer = cechoduration; cechotimer = cechoduration;

View file

@ -2692,7 +2692,7 @@ static boolean MIT_SetCurTitlePics(UINT32 menutype, INT32 level, INT32 *retval,
curhidepics = menupres[menutype].hidetitlepics; curhidepics = menupres[menutype].hidetitlepics;
curttmode = menupres[menutype].ttmode; curttmode = menupres[menutype].ttmode;
curttscale = (menupres[menutype].ttscale != UINT8_MAX ? menupres[menutype].ttscale : ttscale); curttscale = (menupres[menutype].ttscale != UINT8_MAX ? menupres[menutype].ttscale : ttscale);
strncpy(curttname, menupres[menutype].ttname, 9); strncpy(curttname, menupres[menutype].ttname, sizeof(curttname)-1);
curttx = (menupres[menutype].ttx != INT16_MAX ? menupres[menutype].ttx : ttx); curttx = (menupres[menutype].ttx != INT16_MAX ? menupres[menutype].ttx : ttx);
curtty = (menupres[menutype].tty != INT16_MAX ? menupres[menutype].tty : tty); curtty = (menupres[menutype].tty != INT16_MAX ? menupres[menutype].tty : tty);
curttloop = (menupres[menutype].ttloop != INT16_MAX ? menupres[menutype].ttloop : ttloop); curttloop = (menupres[menutype].ttloop != INT16_MAX ? menupres[menutype].ttloop : ttloop);
@ -11282,6 +11282,7 @@ static void M_DrawRoomMenu(void)
if (dot_frame < 0) if (dot_frame < 0)
dot_frame = 0; dot_frame = 0;
if (dot_frame != 3)
strncpy(&text[dot_frame], "...", min(dots, 3 - dot_frame)); strncpy(&text[dot_frame], "...", min(dots, 3 - dot_frame));
} }

View file

@ -378,7 +378,7 @@ typedef struct
char displayname[SKINNAMESIZE+1]; char displayname[SKINNAMESIZE+1];
INT16 skinnum[2]; INT16 skinnum[2];
UINT16 oppositecolor; UINT16 oppositecolor;
char nametag[8]; char nametag[8+1];
patch_t *namepic; patch_t *namepic;
UINT16 tagtextcolor; UINT16 tagtextcolor;
UINT16 tagoutlinecolor; UINT16 tagoutlinecolor;

View file

@ -307,7 +307,7 @@ boolean CL_SendJoin(void)
else else
player2name = cv_playername2.zstring; player2name = cv_playername2.zstring;
strncpy(netbuffer->u.clientcfg.names[0], cv_playername.zstring, MAXPLAYERNAME); strncpy(netbuffer->u.clientcfg.names[0], cv_playername.zstring, sizeof(netbuffer->u.clientcfg.names[0])-1);
strncpy(netbuffer->u.clientcfg.names[1], player2name, MAXPLAYERNAME); strncpy(netbuffer->u.clientcfg.names[1], player2name, MAXPLAYERNAME);
return HSendPacket(servernode, true, 0, sizeof (clientconfig_pak)); return HSendPacket(servernode, true, 0, sizeof (clientconfig_pak));

View file

@ -115,12 +115,12 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime)
netbuffer->u.serverinfo.refusereason = GetRefuseReason(node); netbuffer->u.serverinfo.refusereason = GetRefuseReason(node);
strncpy(netbuffer->u.serverinfo.gametypename, Gametype_Names[gametype], strncpy(netbuffer->u.serverinfo.gametypename, Gametype_Names[gametype],
sizeof netbuffer->u.serverinfo.gametypename); sizeof(netbuffer->u.serverinfo.gametypename)-1);
netbuffer->u.serverinfo.modifiedgame = (UINT8)modifiedgame; netbuffer->u.serverinfo.modifiedgame = (UINT8)modifiedgame;
netbuffer->u.serverinfo.cheatsenabled = CV_CheatsEnabled(); netbuffer->u.serverinfo.cheatsenabled = CV_CheatsEnabled();
netbuffer->u.serverinfo.flags = (dedicated ? SV_DEDICATED : 0); netbuffer->u.serverinfo.flags = (dedicated ? SV_DEDICATED : 0);
strncpy(netbuffer->u.serverinfo.servername, cv_servername.string, strncpy(netbuffer->u.serverinfo.servername, cv_servername.string,
MAXSERVERNAME); sizeof(netbuffer->u.serverinfo.servername)-1);
strncpy(netbuffer->u.serverinfo.mapname, G_BuildMapName(gamemap), 7); strncpy(netbuffer->u.serverinfo.mapname, G_BuildMapName(gamemap), 7);
M_Memcpy(netbuffer->u.serverinfo.mapmd5, mapmd5, 16); M_Memcpy(netbuffer->u.serverinfo.mapmd5, mapmd5, 16);
@ -184,7 +184,9 @@ static void SV_SendPlayerInfo(INT32 node)
} }
netbuffer->u.playerinfo[i].num = i; netbuffer->u.playerinfo[i].num = i;
strncpy(netbuffer->u.playerinfo[i].name, (const char *)&player_names[i], MAXPLAYERNAME+1); memset(netbuffer->u.playerinfo[i].name, 0x00, sizeof(netbuffer->u.playerinfo[i].name));
memcpy(netbuffer->u.playerinfo[i].name, player_names[i], sizeof(player_names[i]));
netbuffer->u.playerinfo[i].name[MAXPLAYERNAME] = '\0'; netbuffer->u.playerinfo[i].name[MAXPLAYERNAME] = '\0';
//fetch IP address //fetch IP address

View file

@ -363,7 +363,7 @@ void P_ParseAnimationDefintion(SINT8 istexture)
// Increase the size to make room for the new animation definition // Increase the size to make room for the new animation definition
maxanims++; maxanims++;
animdefs = (animdef_t *)Z_Realloc(animdefs, sizeof(animdef_t)*(maxanims + 1), PU_STATIC, NULL); animdefs = (animdef_t *)Z_Realloc(animdefs, sizeof(animdef_t)*(maxanims + 1), PU_STATIC, NULL);
strncpy(animdefs[i].startname, animdefsToken, 9); strncpy(animdefs[i].startname, animdefsToken, sizeof(animdefs[i].startname)-1);
} }
// animdefs[i].startname is now set to animdefsToken either way. // animdefs[i].startname is now set to animdefsToken either way.

View file

@ -1910,7 +1910,7 @@ static void S_AddMusicStackEntry(const char *mname, UINT16 mflags, boolean loopi
if (!music_stacks) if (!music_stacks)
{ {
music_stacks = Z_Calloc(sizeof (*mst), PU_MUSIC, NULL); music_stacks = Z_Calloc(sizeof (*mst), PU_MUSIC, NULL);
strncpy(music_stacks->musname, (status == JT_MASTER ? mname : (S_CheckQueue() ? queue_name : mapmusname)), 7); strncpy(music_stacks->musname, (status == JT_MASTER ? mname : (S_CheckQueue() ? queue_name : mapmusname)), sizeof(music_stacks->musname)-1);
music_stacks->musflags = (status == JT_MASTER ? mflags : (S_CheckQueue() ? queue_flags : mapmusflags)); music_stacks->musflags = (status == JT_MASTER ? mflags : (S_CheckQueue() ? queue_flags : mapmusflags));
music_stacks->looping = (status == JT_MASTER ? looping : (S_CheckQueue() ? queue_looping : true)); music_stacks->looping = (status == JT_MASTER ? looping : (S_CheckQueue() ? queue_looping : true));
music_stacks->position = (status == JT_MASTER ? position : (S_CheckQueue() ? queue_position : S_GetMusicPosition())); music_stacks->position = (status == JT_MASTER ? position : (S_CheckQueue() ? queue_position : S_GetMusicPosition()));
@ -2033,7 +2033,7 @@ boolean S_RecallMusic(UINT16 status, boolean fromfirst)
if (result) if (result)
{ {
*entry = *result; *entry = *result;
strncpy(entry->musname, result->musname, 7); memcpy(entry->musname, result->musname, sizeof(entry->musname));
} }
// no result, just grab mapmusname // no result, just grab mapmusname
@ -2255,7 +2255,7 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32
if (S_MusicDisabled()) if (S_MusicDisabled())
return; return;
strncpy(newmusic, mmusic, 7); strncpy(newmusic, mmusic, sizeof(newmusic)-1);
if (LUA_HookMusicChange(music_name, &hook_param)) if (LUA_HookMusicChange(music_name, &hook_param))
return; return;
newmusic[6] = 0; newmusic[6] = 0;

View file

@ -238,7 +238,7 @@ UINT32 S_GetMusicPosition(void);
typedef struct musicstack_s typedef struct musicstack_s
{ {
char musname[7]; char musname[7+1];
UINT16 musflags; UINT16 musflags;
boolean looping; boolean looping;
UINT32 position; UINT32 position;

View file

@ -1700,7 +1700,7 @@ const char *I_GetJoyName(INT32 joyindex)
{ {
tempname = SDL_JoystickNameForIndex(joyindex); tempname = SDL_JoystickNameForIndex(joyindex);
if (tempname) if (tempname)
strncpy(joyname, tempname, 255); strncpy(joyname, tempname, sizeof(joyname)-1);
} }
return joyname; return joyname;
} }

View file

@ -384,13 +384,14 @@ void V_CubeApply(UINT8 *red, UINT8 *green, UINT8 *blue)
const char *R_GetPalname(UINT16 num) const char *R_GetPalname(UINT16 num)
{ {
static char palname[9]; static char palname[8+1];
char newpal[9] = "PLAYPAL"; char newpal[9] = "PLAYPAL\0";
if (num > 0 && num <= 10000) if (num > 0 && num <= 10000)
snprintf(newpal, 8, "PAL%04u", num-1); snprintf(newpal, 8, "PAL%04u", num-1);
strncpy(palname, newpal, 8); strncpy(palname, newpal, sizeof(palname)-1);
palname[8] = 0;
return palname; return palname;
} }