summaryrefslogtreecommitdiff
path: root/src/hexen
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/hexen
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/hexen')
-rw-r--r--src/hexen/am_map.c13
-rw-r--r--src/hexen/h2_main.c6
-rw-r--r--src/hexen/in_lude.c9
-rw-r--r--src/hexen/mn_menu.c2
-rw-r--r--src/hexen/p_acs.c10
-rw-r--r--src/hexen/p_setup.c2
-rw-r--r--src/hexen/p_spec.c5
-rw-r--r--src/hexen/sb_bar.c44
-rw-r--r--src/hexen/sc_man.c2
-rw-r--r--src/hexen/sv_save.c34
10 files changed, 65 insertions, 62 deletions
diff --git a/src/hexen/am_map.c b/src/hexen/am_map.c
index 21b6c45c..cbbb3586 100644
--- a/src/hexen/am_map.c
+++ b/src/hexen/am_map.c
@@ -29,6 +29,7 @@
#include "i_video.h"
#include "i_swap.h"
#include "m_controls.h"
+#include "m_misc.h"
#include "p_local.h"
#include "am_map.h"
#include "am_data.h"
@@ -1474,8 +1475,8 @@ void AM_DrawDeathmatchStats(void)
else
{
MN_DrTextA(PlayerColorText[order[i]], 8, yPosition);
- snprintf(textBuffer, sizeof(textBuffer),
- "%d", fragCount[order[i]]);
+ M_snprintf(textBuffer, sizeof(textBuffer),
+ "%d", fragCount[order[i]]);
MN_DrTextA(textBuffer, 80, yPosition);
yPosition += 10;
}
@@ -1509,19 +1510,19 @@ static void DrawWorldTimer(void)
worldTimer -= minutes * 60;
seconds = worldTimer;
- snprintf(timeBuffer, sizeof(timeBuffer),
- "%.2d : %.2d : %.2d", hours, minutes, seconds);
+ M_snprintf(timeBuffer, sizeof(timeBuffer),
+ "%.2d : %.2d : %.2d", hours, minutes, seconds);
MN_DrTextA(timeBuffer, 240, 8);
if (days)
{
if (days == 1)
{
- snprintf(dayBuffer, sizeof(dayBuffer), "%.2d DAY", days);
+ M_snprintf(dayBuffer, sizeof(dayBuffer), "%.2d DAY", days);
}
else
{
- snprintf(dayBuffer, sizeof(dayBuffer), "%.2d DAYS", days);
+ M_snprintf(dayBuffer, sizeof(dayBuffer), "%.2d DAYS", days);
}
MN_DrTextA(dayBuffer, 240, 20);
if (days >= 5)
diff --git a/src/hexen/h2_main.c b/src/hexen/h2_main.c
index 607bc26b..a7c3dee3 100644
--- a/src/hexen/h2_main.c
+++ b/src/hexen/h2_main.c
@@ -172,7 +172,7 @@ void D_BindVariables(void)
{
char buf[12];
- snprintf(buf, sizeof(buf), "chatmacro%i", i);
+ M_snprintf(buf, sizeof(buf), "chatmacro%i", i);
M_BindVariable(buf, &chat_macros[i]);
}
}
@@ -190,7 +190,7 @@ static void D_SetDefaultSavePath(void)
if (!strcmp(SavePath, ""))
{
SavePath = malloc(10);
- snprintf(SavePath, 10, "hexndata%c", DIR_SEPARATOR);
+ M_snprintf(SavePath, 10, "hexndata%c", DIR_SEPARATOR);
}
}
@@ -632,7 +632,7 @@ void H2_GameLoop(void)
if (M_CheckParm("-debugfile"))
{
char filename[20];
- snprintf(filename, sizeof(filename), "debug%i.txt", consoleplayer);
+ M_snprintf(filename, sizeof(filename), "debug%i.txt", consoleplayer);
debugfile = fopen(filename, "w");
}
I_SetWindowTitle("Hexen");
diff --git a/src/hexen/in_lude.c b/src/hexen/in_lude.c
index b1d0c4c9..fb1b1020 100644
--- a/src/hexen/in_lude.c
+++ b/src/hexen/in_lude.c
@@ -28,6 +28,7 @@
#include "s_sound.h"
#include "i_system.h"
#include "i_video.h"
+#include "m_misc.h"
#include "p_local.h"
#include "v_video.h"
@@ -537,8 +538,8 @@ static void DrNumber(int val, int x, int y, int wrapThresh)
if (!(val < -9 && wrapThresh < 1000))
{
- snprintf(buff, sizeof(buff), "%d",
- val >= wrapThresh ? val % wrapThresh : val);
+ M_snprintf(buff, sizeof(buff), "%d",
+ val >= wrapThresh ? val % wrapThresh : val);
}
MN_DrTextA(buff, x - MN_TextAWidth(buff) / 2, y);
}
@@ -555,8 +556,8 @@ static void DrNumberBold(int val, int x, int y, int wrapThresh)
if (!(val < -9 && wrapThresh < 1000))
{
- snprintf(buff, sizeof(buff), "%d",
- val >= wrapThresh ? val % wrapThresh : val);
+ M_snprintf(buff, sizeof(buff), "%d",
+ val >= wrapThresh ? val % wrapThresh : val);
}
MN_DrTextAYellow(buff, x - MN_TextAWidth(buff) / 2, y);
}
diff --git a/src/hexen/mn_menu.c b/src/hexen/mn_menu.c
index d12d0dc3..75433306 100644
--- a/src/hexen/mn_menu.c
+++ b/src/hexen/mn_menu.c
@@ -685,7 +685,7 @@ static boolean ReadDescriptionForSlot(int slot, char *description)
char name[100];
char versionText[HXS_VERSION_TEXT_LENGTH];
- snprintf(name, sizeof(name), "%shex%d.hxs", SavePath, slot);
+ M_snprintf(name, sizeof(name), "%shex%d.hxs", SavePath, slot);
fp = fopen(name, "rb");
diff --git a/src/hexen/p_acs.c b/src/hexen/p_acs.c
index a9e64517..7ae6a985 100644
--- a/src/hexen/p_acs.c
+++ b/src/hexen/p_acs.c
@@ -443,8 +443,8 @@ boolean P_StartACS(int number, int map, byte * args, mobj_t * activator,
if (infoIndex == -1)
{ // Script not found
//I_Error("P_StartACS: Unknown script number %d", number);
- snprintf(ErrorMsg, sizeof(ErrorMsg),
- "P_STARTACS ERROR: UNKNOWN SCRIPT %d", number);
+ M_snprintf(ErrorMsg, sizeof(ErrorMsg),
+ "P_STARTACS ERROR: UNKNOWN SCRIPT %d", number);
P_SetMessage(&players[consoleplayer], ErrorMsg, true);
}
statePtr = &ACSInfo[infoIndex].state;
@@ -540,8 +540,8 @@ boolean P_StartLockedACS(line_t * line, byte * args, mobj_t * mo, int side)
{
if (!(mo->player->keys & (1 << (lock - 1))))
{
- snprintf(LockedBuffer, sizeof(LockedBuffer),
- "YOU NEED THE %s\n", TextKeyMessages[lock - 1]);
+ M_snprintf(LockedBuffer, sizeof(LockedBuffer),
+ "YOU NEED THE %s\n", TextKeyMessages[lock - 1]);
P_SetMessage(mo->player, LockedBuffer, true);
S_StartSound(mo, SFX_DOOR_LOCKED);
return false;
@@ -1692,7 +1692,7 @@ static int CmdPrintNumber(void)
{
char tempStr[16];
- snprintf(tempStr, sizeof(tempStr), "%d", Pop());
+ M_snprintf(tempStr, sizeof(tempStr), "%d", Pop());
M_StringConcat(PrintBuffer, tempStr, sizeof(PrintBuffer));
return SCRIPT_CONTINUE;
}
diff --git a/src/hexen/p_setup.c b/src/hexen/p_setup.c
index cd075651..181e19fe 100644
--- a/src/hexen/p_setup.c
+++ b/src/hexen/p_setup.c
@@ -700,7 +700,7 @@ void P_SetupLevel(int episode, int map, int playermask, skill_t skill)
P_InitThinkers();
leveltime = 0;
- snprintf(lumpname, sizeof(lumpname), "MAP%02d", map);
+ M_snprintf(lumpname, sizeof(lumpname), "MAP%02d", map);
lumpnum = W_GetNumForName(lumpname);
//
// Begin processing map lumps
diff --git a/src/hexen/p_spec.c b/src/hexen/p_spec.c
index 06a4a6ff..58f3defe 100644
--- a/src/hexen/p_spec.c
+++ b/src/hexen/p_spec.c
@@ -27,6 +27,7 @@
#include "h2def.h"
#include "i_system.h"
+#include "m_misc.h"
#include "p_local.h"
#include "s_sound.h"
@@ -428,8 +429,8 @@ static boolean CheckedLockedDoor(mobj_t * mo, byte lock)
}
if (!(mo->player->keys & (1 << (lock - 1))))
{
- snprintf(LockedBuffer, sizeof(LockedBuffer),
- "YOU NEED THE %s\n", TextKeyMessages[lock - 1]);
+ M_snprintf(LockedBuffer, sizeof(LockedBuffer),
+ "YOU NEED THE %s\n", TextKeyMessages[lock - 1]);
P_SetMessage(mo->player, LockedBuffer, true);
S_StartSound(mo, SFX_DOOR_LOCKED);
return false;
diff --git a/src/hexen/sb_bar.c b/src/hexen/sb_bar.c
index b35c1f51..5d2438aa 100644
--- a/src/hexen/sb_bar.c
+++ b/src/hexen/sb_bar.c
@@ -640,20 +640,20 @@ static void DrawSoundInfo(void)
MN_DrTextA("------", xPos[0], y);
continue;
}
- snprintf(text, sizeof(text), "%s", c->name);
+ M_snprintf(text, sizeof(text), "%s", c->name);
M_ForceUppercase(text);
MN_DrTextA(text, xPos[x++], y);
- snprintf(text, sizeof(text), "%d", c->mo->type);
+ M_snprintf(text, sizeof(text), "%d", c->mo->type);
MN_DrTextA(text, xPos[x++], y);
- snprintf(text, sizeof(text), "%d", c->mo->x >> FRACBITS);
+ M_snprintf(text, sizeof(text), "%d", c->mo->x >> FRACBITS);
MN_DrTextA(text, xPos[x++], y);
- snprintf(text, sizeof(text), "%d", c->mo->y >> FRACBITS);
+ M_snprintf(text, sizeof(text), "%d", c->mo->y >> FRACBITS);
MN_DrTextA(text, xPos[x++], y);
- snprintf(text, sizeof(text), "%d", (int) c->id);
+ M_snprintf(text, sizeof(text), "%d", (int) c->id);
MN_DrTextA(text, xPos[x++], y);
- snprintf(text, sizeof(text), "%d", c->priority);
+ M_snprintf(text, sizeof(text), "%d", c->priority);
MN_DrTextA(text, xPos[x++], y);
- snprintf(text, sizeof(text), "%d", c->distance);
+ M_snprintf(text, sizeof(text), "%d", c->distance);
MN_DrTextA(text, xPos[x++], y);
}
UpdateState |= I_FULLSCRN;
@@ -1738,7 +1738,7 @@ static void CheatWarpFunc(player_t * player, Cheat_t * cheat)
P_SetMessage(player, TXT_CHEATBADINPUT, true);
return;
}
- snprintf(mapName, sizeof(mapName), "MAP%02d", map);
+ M_snprintf(mapName, sizeof(mapName), "MAP%02d", map);
if (W_CheckNumForName(mapName) == -1)
{ // Can't find
P_SetMessage(player, TXT_CHEATNOMAP, true);
@@ -1769,7 +1769,7 @@ static void CheatMassacreFunc(player_t * player, Cheat_t * cheat)
char buffer[80];
count = P_Massacre();
- snprintf(buffer, sizeof(buffer), "%d MONSTERS KILLED\n", count);
+ M_snprintf(buffer, sizeof(buffer), "%d MONSTERS KILLED\n", count);
P_SetMessage(player, buffer, true);
}
@@ -1857,12 +1857,12 @@ static void CheatVersionFunc(player_t * player, Cheat_t * cheat)
static void CheatDebugFunc(player_t * player, Cheat_t * cheat)
{
char textBuffer[50];
- snprintf(textBuffer, sizeof(textBuffer),
- "MAP %d (%d) X:%5d Y:%5d Z:%5d",
- P_GetMapWarpTrans(gamemap),
- gamemap,
- player->mo->x >> FRACBITS,
- player->mo->y >> FRACBITS, player->mo->z >> FRACBITS);
+ M_snprintf(textBuffer, sizeof(textBuffer),
+ "MAP %d (%d) X:%5d Y:%5d Z:%5d",
+ P_GetMapWarpTrans(gamemap),
+ gamemap,
+ player->mo->x >> FRACBITS,
+ player->mo->y >> FRACBITS, player->mo->z >> FRACBITS);
P_SetMessage(player, textBuffer, true);
}
@@ -1897,8 +1897,8 @@ static void CheatScriptFunc3(player_t * player, Cheat_t * cheat)
if (P_StartACS(script, 0, script_args, player->mo, NULL, 0))
{
- snprintf(textBuffer, sizeof(textBuffer),
- "RUNNING SCRIPT %.2d", script);
+ M_snprintf(textBuffer, sizeof(textBuffer),
+ "RUNNING SCRIPT %.2d", script);
P_SetMessage(player, textBuffer, true);
}
}
@@ -1930,8 +1930,8 @@ static void CheatTrackFunc1(player_t * player, Cheat_t * cheat)
P_SetMessage(player, "ERROR INITIALIZING CD", true);
}
- snprintf(buffer, sizeof(buffer), "ENTER DESIRED CD TRACK (%.2d - %.2d):\n",
- I_CDMusFirstTrack(), I_CDMusLastTrack());
+ M_snprintf(buffer, sizeof(buffer), "ENTER DESIRED CD TRACK (%.2d - %.2d):\n",
+ I_CDMusFirstTrack(), I_CDMusLastTrack());
P_SetMessage(player, buffer, true);
}
@@ -1968,14 +1968,14 @@ static void CheatTrackFunc2(player_t * player, Cheat_t * cheat)
if (!S_StartCustomCDTrack(track))
{
- snprintf(buffer, sizeof(buffer),
- "ERROR WHILE TRYING TO PLAY CD TRACK: %.2d\n", track);
+ M_snprintf(buffer, sizeof(buffer),
+ "ERROR WHILE TRYING TO PLAY CD TRACK: %.2d\n", track);
P_SetMessage(player, buffer, true);
}
else
{
// No error encountered while attempting to play the track
- snprintf(buffer, sizeof(buffer), "PLAYING TRACK: %.2d\n", track);
+ M_snprintf(buffer, sizeof(buffer), "PLAYING TRACK: %.2d\n", track);
P_SetMessage(player, buffer, true);
}
}
diff --git a/src/hexen/sc_man.c b/src/hexen/sc_man.c
index 35f5ec0b..bf3574c3 100644
--- a/src/hexen/sc_man.c
+++ b/src/hexen/sc_man.c
@@ -88,7 +88,7 @@ void SC_Open(char *name)
if (sc_FileScripts == true)
{
- snprintf(fileName, sizeof(fileName), "%s%s.txt", sc_ScriptsDir, name);
+ M_snprintf(fileName, sizeof(fileName), "%s%s.txt", sc_ScriptsDir, name);
SC_OpenFile(fileName);
}
else
diff --git a/src/hexen/sv_save.c b/src/hexen/sv_save.c
index dd707398..1aecc5cc 100644
--- a/src/hexen/sv_save.c
+++ b/src/hexen/sv_save.c
@@ -1940,7 +1940,7 @@ void SV_SaveGame(int slot, char *description)
unsigned int i;
// Open the output file
- snprintf(fileName, sizeof(fileName), "%shex6.hxs", SavePath);
+ M_snprintf(fileName, sizeof(fileName), "%shex6.hxs", SavePath);
OpenStreamOut(fileName);
// Write game save description
@@ -2000,7 +2000,7 @@ void SV_SaveMap(boolean savePlayers)
SavingPlayers = savePlayers;
// Open the output file
- snprintf(fileName, sizeof(fileName), "%shex6%02d.hxs", SavePath, gamemap);
+ M_snprintf(fileName, sizeof(fileName), "%shex6%02d.hxs", SavePath, gamemap);
OpenStreamOut(fileName);
// Place a header marker
@@ -2048,7 +2048,7 @@ void SV_LoadGame(int slot)
}
// Create the name
- snprintf(fileName, sizeof(fileName), "%shex6.hxs", SavePath);
+ M_snprintf(fileName, sizeof(fileName), "%shex6.hxs", SavePath);
// Load the file
M_ReadFile(fileName, &SaveBuffer);
@@ -2192,7 +2192,7 @@ void SV_MapTeleport(int map, int position)
TargetPlayerAddrs = NULL;
gamemap = map;
- snprintf(fileName, sizeof(fileName), "%shex6%02d.hxs", SavePath, gamemap);
+ M_snprintf(fileName, sizeof(fileName), "%shex6%02d.hxs", SavePath, gamemap);
if (!deathmatch && ExistingFile(fileName))
{ // Unarchive map
SV_LoadMap();
@@ -2342,7 +2342,7 @@ boolean SV_RebornSlotAvailable(void)
{
char fileName[100];
- snprintf(fileName, sizeof(fileName), "%shex%d.hxs", SavePath, REBORN_SLOT);
+ M_snprintf(fileName, sizeof(fileName), "%shex%d.hxs", SavePath, REBORN_SLOT);
return ExistingFile(fileName);
}
@@ -2363,7 +2363,7 @@ void SV_LoadMap(void)
RemoveAllThinkers();
// Create the name
- snprintf(fileName, sizeof(fileName), "%shex6%02d.hxs", SavePath, gamemap);
+ M_snprintf(fileName, sizeof(fileName), "%shex6%02d.hxs", SavePath, gamemap);
// Load the file
M_ReadFile(fileName, &SaveBuffer);
@@ -3204,11 +3204,11 @@ static void ClearSaveSlot(int slot)
for (i = 0; i < MAX_MAPS; i++)
{
- snprintf(fileName, sizeof(fileName),
- "%shex%d%02d.hxs", SavePath, slot, i);
+ M_snprintf(fileName, sizeof(fileName),
+ "%shex%d%02d.hxs", SavePath, slot, i);
remove(fileName);
}
- snprintf(fileName, sizeof(fileName), "%shex%d.hxs", SavePath, slot);
+ M_snprintf(fileName, sizeof(fileName), "%shex%d.hxs", SavePath, slot);
remove(fileName);
}
@@ -3228,21 +3228,21 @@ static void CopySaveSlot(int sourceSlot, int destSlot)
for (i = 0; i < MAX_MAPS; i++)
{
- snprintf(sourceName, sizeof(sourceName),
- "%shex%d%02d.hxs", SavePath, sourceSlot, i);
+ M_snprintf(sourceName, sizeof(sourceName),
+ "%shex%d%02d.hxs", SavePath, sourceSlot, i);
if (ExistingFile(sourceName))
{
- snprintf(destName, sizeof(destName),
- "%shex%d%02d.hxs", SavePath, destSlot, i);
+ M_snprintf(destName, sizeof(destName),
+ "%shex%d%02d.hxs", SavePath, destSlot, i);
CopyFile(sourceName, destName);
}
}
- snprintf(sourceName, sizeof(sourceName),
- "%shex%d.hxs", SavePath, sourceSlot);
+ M_snprintf(sourceName, sizeof(sourceName),
+ "%shex%d.hxs", SavePath, sourceSlot);
if (ExistingFile(sourceName))
{
- snprintf(destName, sizeof(destName),
- "%shex%d.hxs", SavePath, destSlot);
+ M_snprintf(destName, sizeof(destName),
+ "%shex%d.hxs", SavePath, destSlot);
CopyFile(sourceName, destName);
}
}