diff options
author | Simon Howard | 2014-03-29 21:49:57 -0400 |
---|---|---|
committer | Simon Howard | 2014-03-29 21:49:57 -0400 |
commit | eb3a4033c7d6f1d5e042edd5f416bbc257e40975 (patch) | |
tree | 9b6871a887655f88b4dbb1c5412469924604fb7e /src/strife/d_main.c | |
parent | 1e5e0a565cbcaf4f8aafa5a12c84e987aa822e13 (diff) | |
download | chocolate-doom-eb3a4033c7d6f1d5e042edd5f416bbc257e40975.tar.gz chocolate-doom-eb3a4033c7d6f1d5e042edd5f416bbc257e40975.tar.bz2 chocolate-doom-eb3a4033c7d6f1d5e042edd5f416bbc257e40975.zip |
strife: Eliminate use of unsafe string functions.
Eliminate use of strcpy, strcat, strncpy, and use the new safe
alternatives.
Diffstat (limited to 'src/strife/d_main.c')
-rw-r--r-- | src/strife/d_main.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/strife/d_main.c b/src/strife/d_main.c index 6769c8ed..edd01f87 100644 --- a/src/strife/d_main.c +++ b/src/strife/d_main.c @@ -783,20 +783,26 @@ static char *GetGameName(char *gamename) if (deh_sub != banners[i]) { + size_t gamename_size; + // Has been replaced // We need to expand via printf to include the Doom version // number // We also need to cut off spaces to get the basic name - gamename = Z_Malloc(strlen(deh_sub) + 10, PU_STATIC, 0); - sprintf(gamename, deh_sub, STRIFE_VERSION / 100, STRIFE_VERSION % 100); + gamename_size = strlen(deh_sub) + 10; + gamename = Z_Malloc(gamename_size, PU_STATIC, 0); + snprintf(gamename, gamename_size, deh_sub, + STRIFE_VERSION / 100, STRIFE_VERSION % 100); while (gamename[0] != '\0' && isspace(gamename[0])) - strcpy(gamename, gamename+1); + { + memmove(gamename, gamename + 1, gamename_size - 1); + } while (gamename[0] != '\0' && isspace(gamename[strlen(gamename)-1])) gamename[strlen(gamename) - 1] = '\0'; - + return gamename; } } @@ -848,7 +854,7 @@ void D_IdentifyVersion(void) // how the heck is Choco surviving without this routine? sepchar = M_GetFilePath(iwad, filename, len); filename[strlen(filename)] = sepchar; - strcat(filename, "voices.wad"); + M_StringConcat(filename, "voices.wad", sizeof(filename)); if(!M_FileExists(filename)) disable_voices = 1; @@ -1602,17 +1608,17 @@ void D_DoomMain (void) { if (!strcasecmp(myargv[p+1] + strlen(myargv[p+1]) - 4, ".lmp")) { - strcpy(file, myargv[p + 1]); + M_StringCopy(file, myargv[p + 1], sizeof(file)); } else { - sprintf (file,"%s.lmp", myargv[p+1]); + snprintf(file, sizeof(file), "%s.lmp", myargv[p+1]); } if (D_AddFile (file)) { - strncpy(demolumpname, lumpinfo[numlumps - 1].name, 8); - demolumpname[8] = '\0'; + M_StringCopy(demolumpname, lumpinfo[numlumps - 1].name, + sizeof(demolumpname)); printf("Playing demo %s.\n", file); } @@ -1622,8 +1628,7 @@ void D_DoomMain (void) // the demo in the same way as Vanilla Doom. This makes // tricks like "-playdemo demo1" possible. - strncpy(demolumpname, myargv[p + 1], 8); - demolumpname[8] = '\0'; + M_StringCopy(demolumpname, myargv[p + 1], sizeof(demolumpname)); } } |