summaryrefslogtreecommitdiff
path: root/src/strife/g_game.c
diff options
context:
space:
mode:
authorSimon Howard2014-04-01 20:43:45 -0400
committerSimon Howard2014-04-01 20:43:45 -0400
commit8eb3200286d523379295143ce3f44d77ce036d4b (patch)
treeac0edb56027f285425d896e12a1b14d78ad294b9 /src/strife/g_game.c
parent565a1f08566520147a5abff5744dbcc256e5030c (diff)
downloadchocolate-doom-8eb3200286d523379295143ce3f44d77ce036d4b.tar.gz
chocolate-doom-8eb3200286d523379295143ce3f44d77ce036d4b.tar.bz2
chocolate-doom-8eb3200286d523379295143ce3f44d77ce036d4b.zip
Replace all snprintf() calls with M_snprintf().
The Windows API has an _snprintf function that is not the same as Unix's snprintf(): if the string is truncated then no trailing NUL character is appended. This makes the function unsafe. Define a replacement/wrapper called M_snprintf that works the same but always appends a trailing NUL, for safety on Windows and other OSes that behave like this. Do the same thing for vsnprintf(), and update HACKING to list snprintf/vsnprintf as forbidden functions. This fixes #375; thanks to Quasar for pointing out the different behavior of these functions.
Diffstat (limited to 'src/strife/g_game.c')
-rw-r--r--src/strife/g_game.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/strife/g_game.c b/src/strife/g_game.c
index 23e0cef9..c67d7be1 100644
--- a/src/strife/g_game.c
+++ b/src/strife/g_game.c
@@ -985,8 +985,8 @@ void G_Ticker (void)
{
static char turbomessage[80];
extern char player_names[8][16];
- snprintf(turbomessage, sizeof(turbomessage),
- "%s is turbo!", player_names[i]);
+ M_snprintf(turbomessage, sizeof(turbomessage),
+ "%s is turbo!", player_names[i]);
players[consoleplayer].message = turbomessage;
turbodetected[i] = false;
}
@@ -1290,7 +1290,7 @@ void G_LoadPath(int map)
char mapbuf[33];
memset(mapbuf, 0, sizeof(mapbuf));
- snprintf(mapbuf, sizeof(mapbuf), "%d", map);
+ M_snprintf(mapbuf, sizeof(mapbuf), "%d", map);
// haleyjd: free if already set, and use M_SafeFilePath
if(loadpath)
@@ -1805,7 +1805,7 @@ void G_DoSaveGame (char *path)
// [STRIFE] custom save file path logic
memset(gamemapstr, 0, sizeof(gamemapstr));
- snprintf(gamemapstr, sizeof(gamemapstr), "%d", gamemap);
+ M_snprintf(gamemapstr, sizeof(gamemapstr), "%d", gamemap);
savegame_file = M_SafeFilePath(path, gamemapstr);
// [STRIFE] write the "current" file, which tells which hub map
@@ -1870,7 +1870,7 @@ void G_DoSaveGame (char *path)
// [STRIFE]: custom message logic
if(!strcmp(path, savepath))
{
- snprintf(savename, sizeof(savename), "%s saved.", character_name);
+ M_snprintf(savename, sizeof(savename), "%s saved.", character_name);
players[consoleplayer].message = savename;
}
@@ -2195,7 +2195,7 @@ void G_RecordDemo (char* name)
usergame = false;
demoname_size = strlen(name) + 5;
demoname = Z_Malloc(demoname_size, PU_STATIC, NULL);
- snprintf(demoname, demoname_size, "%s.lmp", name);
+ M_snprintf(demoname, demoname_size, "%s.lmp", name);
maxsize = 0x20000;
//!
@@ -2290,8 +2290,8 @@ static char *DemoVersionDescription(int version)
}
// Unknown version. Who knows?
- snprintf(resultbuf, sizeof(resultbuf),
- "%i.%i (unknown)", version / 100, version % 100);
+ M_snprintf(resultbuf, sizeof(resultbuf),
+ "%i.%i (unknown)", version / 100, version % 100);
return resultbuf;
}