Fix various gcc-9 -Wformat-truncation warnings

This commit is contained in:
Kp 2019-05-06 00:36:16 +00:00
parent 5ea591af18
commit 2c91eda5bc
4 changed files with 16 additions and 13 deletions

View file

@ -151,7 +151,8 @@ static void cmd_parse(char *input)
/* Strip leading spaces */
while( isspace(*input) ) { ++input; }
strncpy( buffer, input, sizeof(buffer) );
buffer[sizeof(buffer) - 1] = 0;
strncpy(buffer, input, sizeof(buffer) - 1);
//printf("lead strip \"%s\"\n",buffer);
l = strlen(buffer);
@ -343,7 +344,8 @@ static void cmd_alias(unsigned long argc, const char *const *const argv)
if (i.second)
{
alias = (i.first->second = make_unique<cmd_alias_t>()).get();
strncpy(alias->name, argv[1], sizeof(alias->name));
alias->name[sizeof(alias->name) - 1] = 0;
strncpy(alias->name, argv[1], sizeof(alias->name) - 1);
}
alias->value.reset(d_strdup(buf));
}

View file

@ -661,7 +661,7 @@ void piggy_init_pigfile(const char *filename)
#endif
}
strncpy(Current_pigfile,filename,sizeof(Current_pigfile));
strncpy(Current_pigfile, filename, sizeof(Current_pigfile) - 1);
N_bitmaps = PHYSFSX_readInt(Piggy_fp);
@ -734,7 +734,7 @@ void piggy_new_pigfile(char *pigname)
Piggy_bitmap_cache_next = 0; //free up cache
strncpy(Current_pigfile,pigname,sizeof(Current_pigfile));
strncpy(Current_pigfile, pigname, sizeof(Current_pigfile) - 1);
Piggy_fp = PHYSFSX_openReadBuffered(pigname);

View file

@ -566,7 +566,8 @@ static void briefing_init(briefing *br, short level_num)
br->level_num = 0; // for start of game stuff
br->cur_screen = 0;
strncpy(br->background_name, DEFAULT_BRIEFING_BKG, sizeof(br->background_name));
br->background_name[sizeof(br->background_name) - 1] = 0;
strncpy(br->background_name, DEFAULT_BRIEFING_BKG, sizeof(br->background_name) - 1);
#if defined(DXX_BUILD_DESCENT_II)
br->robot_playing = 0;
#endif
@ -1308,8 +1309,7 @@ static int load_briefing_screen(grs_canvas &canvas, briefing *const br, const ch
if (!PHYSFSX_exists(fname2,1))
snprintf(fname2, sizeof(char)*PATH_MAX, "%s", fname);
}
if (d_stricmp(br->background_name, fname2))
strncpy (br->background_name,fname2, sizeof(br->background_name));
strncpy(br->background_name, fname2, sizeof(br->background_name) - 1);
if ((!d_stricmp(fname2, "brief02.pcx") || !d_stricmp(fname2, "brief02h.pcx")) && cheats.baldguy &&
(bald_guy_load("btexture.xxx", &br->background, gr_palette) == PCX_ERROR_NONE))
@ -1345,8 +1345,7 @@ static int load_briefing_screen(grs_canvas &canvas, briefing *const br, const ch
int pcx_error;
free_briefing_screen(br);
if (d_stricmp(br->background_name, fname))
strncpy (br->background_name,fname, sizeof(br->background_name));
strncpy(br->background_name, fname, sizeof(br->background_name) - 1);
if ((pcx_error = pcx_read_bitmap(fname, br->background, gr_palette))!=PCX_ERROR_NONE)
Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n",fname, pcx_errormsg(pcx_error), pcx_error);

View file

@ -150,15 +150,17 @@ bool PHYSFSX_init(int argc, char *argv[])
if (path[0] == '~') // yes, this tilde can be put before non-unix paths.
{
const char *home = PHYSFS_getUserDir();
strcpy(fullPath, home); // prepend home to the path
path++;
// prepend home to the path
if (*path == *PHYSFS_getDirSeparator())
path++;
strncat(fullPath, path, PATH_MAX + 5 - strlen(home));
snprintf(fullPath, sizeof(fullPath), "%s%s", home, path);
}
else
strncpy(fullPath, path, PATH_MAX + 5);
{
fullPath[sizeof(fullPath) - 1] = 0;
strncpy(fullPath, path, sizeof(fullPath) - 1);
}
PHYSFS_setWriteDir(fullPath);
if (!(writedir = PHYSFS_getWriteDir()))