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/m_menu.c | 73 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 32 deletions(-) (limited to 'src/doom/m_menu.c') diff --git a/src/doom/m_menu.c b/src/doom/m_menu.c index c1329953..93941b3b 100644 --- a/src/doom/m_menu.c +++ b/src/doom/m_menu.c @@ -41,9 +41,10 @@ #include "i_system.h" #include "i_timer.h" #include "i_video.h" -#include "z_zone.h" +#include "m_misc.h" #include "v_video.h" #include "w_wad.h" +#include "z_zone.h" #include "r_local.h" @@ -515,15 +516,15 @@ void M_ReadSaveStrings(void) for (i = 0;i < load_end;i++) { - strcpy(name, P_SaveGameFile(i)); + M_StringCopy(name, P_SaveGameFile(i), sizeof(name)); handle = fopen(name, "rb"); - if (handle == NULL) - { - strcpy(&savegamestrings[i][0], EMPTYSTRING); - LoadMenu[i].status = 0; - continue; - } + if (handle == NULL) + { + M_StringCopy(savegamestrings[i], EMPTYSTRING, SAVESTRINGSIZE); + LoadMenu[i].status = 0; + continue; + } fread(&savegamestrings[i], 1, SAVESTRINGSIZE, handle); fclose(handle); LoadMenu[i].status = 1; @@ -580,7 +581,7 @@ void M_LoadSelect(int choice) { char name[256]; - strcpy(name, P_SaveGameFile(choice)); + M_StringCopy(name, P_SaveGameFile(choice), sizeof(name)); G_LoadGame (name); M_ClearMenus (); @@ -645,8 +646,8 @@ void M_SaveSelect(int choice) saveStringEnter = 1; saveSlot = choice; - strcpy(saveOldString,savegamestrings[choice]); - if (!strcmp(savegamestrings[choice],EMPTYSTRING)) + M_StringCopy(saveOldString,savegamestrings[choice], SAVESTRINGSIZE); + if (!strcmp(savegamestrings[choice], EMPTYSTRING)) savegamestrings[choice][0] = 0; saveCharIndex = strlen(savegamestrings[choice]); } @@ -1594,12 +1595,13 @@ boolean M_Responder (event_t* ev) savegamestrings[saveSlot][saveCharIndex] = 0; } break; - - case KEY_ESCAPE: - saveStringEnter = 0; - strcpy(&savegamestrings[saveSlot][0],saveOldString); - break; - + + case KEY_ESCAPE: + saveStringEnter = 0; + M_StringCopy(savegamestrings[saveSlot], saveOldString, + SAVESTRINGSIZE); + break; + case KEY_ENTER: saveStringEnter = 0; if (savegamestrings[saveSlot][0]) @@ -1986,21 +1988,28 @@ void M_Drawer (void) { int foundnewline = 0; - for (i = 0; i < strlen(messageString + start); i++) - if (messageString[start + i] == '\n') - { - memset(string, 0, sizeof(string)); - strncpy(string, messageString + start, i); - foundnewline = 1; - start += i + 1; - break; - } - - if (!foundnewline) - { - strcpy(string, messageString + start); - start += strlen(string); - } + for (i = 0; i < strlen(messageString + start); i++) + { + if (messageString[start + i] == '\n') + { + M_StringCopy(string, messageString + start, + sizeof(string)); + if (i < sizeof(string)) + { + string[i] = '\0'; + } + + foundnewline = 1; + start += i + 1; + break; + } + } + + if (!foundnewline) + { + M_StringCopy(string, messageString + start, sizeof(string)); + start += strlen(string); + } x = 160 - M_StringWidth(string) / 2; M_WriteText(x, y, string); -- cgit v1.2.3