From 4465be140a27e47aa8bed15be4e58064297c7d94 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 30 Mar 2014 18:21:42 -0400 Subject: doom: Eliminate use of sprintf(). Use snprintf() or other functions in place of sprintf(). This is part of fixing #371. --- src/doom/p_saveg.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/doom/p_saveg.c') diff --git a/src/doom/p_saveg.c b/src/doom/p_saveg.c index 7dd386a3..5fa70fea 100644 --- a/src/doom/p_saveg.c +++ b/src/doom/p_saveg.c @@ -38,6 +38,7 @@ // State. #include "doomstat.h" #include "g_game.h" +#include "m_misc.h" #include "r_state.h" #define SAVEGAME_EOF 0x1d @@ -57,11 +58,9 @@ char *P_TempSaveGameFile(void) if (filename == NULL) { - filename = malloc(strlen(savegamedir) + 32); + filename = M_StringJoin(savegamedir, "temp.dsg", NULL); } - sprintf(filename, "%stemp.dsg", savegamedir); - return filename; } @@ -70,16 +69,17 @@ char *P_TempSaveGameFile(void) char *P_SaveGameFile(int slot) { static char *filename = NULL; + static size_t filename_size = 0; char basename[32]; if (filename == NULL) { - filename = malloc(strlen(savegamedir) + 32); + filename_size = strlen(savegamedir) + 32; + filename = malloc(filename_size); } DEH_snprintf(basename, 32, SAVEGAMENAME "%d.dsg", slot); - - sprintf(filename, "%s%s", savegamedir, basename); + snprintf(filename, filename_size, "%s%s", savegamedir, basename); return filename; } @@ -1363,7 +1363,7 @@ void P_WriteSaveGameHeader(char *description) saveg_write8(0); memset(name, 0, sizeof(name)); - sprintf(name, "version %i", G_VanillaVersionCode()); + snprintf(name, sizeof(name), "version %i", G_VanillaVersionCode()); for (i=0; i