From 040ca1cfb5a3e1be7d05bcd90eaa4f01fb68437a Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 29 Mar 2014 21:23:29 -0400 Subject: doom: Eliminate use of unsafe string functions. Eliminate use of strcpy, strcat, strncpy, and use the new safe alternatives. --- src/doom/d_main.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/doom/d_main.c') diff --git a/src/doom/d_main.c b/src/doom/d_main.c index 60d93696..17dbd170 100644 --- a/src/doom/d_main.c +++ b/src/doom/d_main.c @@ -659,22 +659,28 @@ static char *GetGameName(char *gamename) if (deh_sub != banners[i]) { + size_t gamename_size; int version; // 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); + gamename_size = strlen(deh_sub) + 10; + gamename = Z_Malloc(gamename_size, PU_STATIC, 0); version = G_VanillaVersionCode(); sprintf(gamename, deh_sub, version / 100, 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; } } -- cgit v1.2.3