diff options
author | Simon Howard | 2014-03-30 19:00:49 -0400 |
---|---|---|
committer | Simon Howard | 2014-03-30 19:00:49 -0400 |
commit | 01ae851bf998330a9ca95467e238c507aa55cae1 (patch) | |
tree | 3fe17da2cdd49ea725c7a6d044ca4885ce024401 /src/hexen | |
parent | 6bb5f78bd2bdf10ddbb087171c6f640d425c9d40 (diff) | |
download | chocolate-doom-01ae851bf998330a9ca95467e238c507aa55cae1.tar.gz chocolate-doom-01ae851bf998330a9ca95467e238c507aa55cae1.tar.bz2 chocolate-doom-01ae851bf998330a9ca95467e238c507aa55cae1.zip |
hexen: Eliminate use of sprintf().
Use snprintf() in place of sprintf(). This is part of fixing #371.
Diffstat (limited to 'src/hexen')
-rw-r--r-- | src/hexen/am_map.c | 10 | ||||
-rw-r--r-- | src/hexen/h2_main.c | 6 | ||||
-rw-r--r-- | src/hexen/in_lude.c | 6 | ||||
-rw-r--r-- | src/hexen/mn_menu.c | 2 | ||||
-rw-r--r-- | src/hexen/p_acs.c | 7 | ||||
-rw-r--r-- | src/hexen/p_setup.c | 2 | ||||
-rw-r--r-- | src/hexen/p_spec.c | 3 | ||||
-rw-r--r-- | src/hexen/sb_bar.c | 39 | ||||
-rw-r--r-- | src/hexen/sc_man.c | 2 | ||||
-rw-r--r-- | src/hexen/sv_save.c | 29 |
10 files changed, 60 insertions, 46 deletions
diff --git a/src/hexen/am_map.c b/src/hexen/am_map.c index 465df9ba..21b6c45c 100644 --- a/src/hexen/am_map.c +++ b/src/hexen/am_map.c @@ -1474,7 +1474,8 @@ void AM_DrawDeathmatchStats(void) else { MN_DrTextA(PlayerColorText[order[i]], 8, yPosition); - sprintf(textBuffer, "%d", fragCount[order[i]]); + snprintf(textBuffer, sizeof(textBuffer), + "%d", fragCount[order[i]]); MN_DrTextA(textBuffer, 80, yPosition); yPosition += 10; } @@ -1508,18 +1509,19 @@ static void DrawWorldTimer(void) worldTimer -= minutes * 60; seconds = worldTimer; - sprintf(timeBuffer, "%.2d : %.2d : %.2d", hours, minutes, seconds); + snprintf(timeBuffer, sizeof(timeBuffer), + "%.2d : %.2d : %.2d", hours, minutes, seconds); MN_DrTextA(timeBuffer, 240, 8); if (days) { if (days == 1) { - sprintf(dayBuffer, "%.2d DAY", days); + snprintf(dayBuffer, sizeof(dayBuffer), "%.2d DAY", days); } else { - sprintf(dayBuffer, "%.2d DAYS", days); + 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 f6351fae..607bc26b 100644 --- a/src/hexen/h2_main.c +++ b/src/hexen/h2_main.c @@ -172,7 +172,7 @@ void D_BindVariables(void) { char buf[12]; - sprintf(buf, "chatmacro%i", i); + 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); - sprintf(SavePath, "hexndata%c", DIR_SEPARATOR); + snprintf(SavePath, 10, "hexndata%c", DIR_SEPARATOR); } } @@ -632,7 +632,7 @@ void H2_GameLoop(void) if (M_CheckParm("-debugfile")) { char filename[20]; - sprintf(filename, "debug%i.txt", consoleplayer); + 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 4164d549..b1d0c4c9 100644 --- a/src/hexen/in_lude.c +++ b/src/hexen/in_lude.c @@ -537,7 +537,8 @@ static void DrNumber(int val, int x, int y, int wrapThresh) if (!(val < -9 && wrapThresh < 1000)) { - sprintf(buff, "%d", val >= wrapThresh ? val % wrapThresh : val); + snprintf(buff, sizeof(buff), "%d", + val >= wrapThresh ? val % wrapThresh : val); } MN_DrTextA(buff, x - MN_TextAWidth(buff) / 2, y); } @@ -554,7 +555,8 @@ static void DrNumberBold(int val, int x, int y, int wrapThresh) if (!(val < -9 && wrapThresh < 1000)) { - sprintf(buff, "%d", val >= wrapThresh ? val % wrapThresh : val); + 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 0456a52f..d12d0dc3 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]; - sprintf(name, "%shex%d.hxs", SavePath, slot); + 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 27b07682..a9e64517 100644 --- a/src/hexen/p_acs.c +++ b/src/hexen/p_acs.c @@ -443,7 +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); - sprintf(ErrorMsg, "P_STARTACS ERROR: UNKNOWN SCRIPT %d", number); + snprintf(ErrorMsg, sizeof(ErrorMsg), + "P_STARTACS ERROR: UNKNOWN SCRIPT %d", number); P_SetMessage(&players[consoleplayer], ErrorMsg, true); } statePtr = &ACSInfo[infoIndex].state; @@ -539,8 +540,8 @@ boolean P_StartLockedACS(line_t * line, byte * args, mobj_t * mo, int side) { if (!(mo->player->keys & (1 << (lock - 1)))) { - sprintf(LockedBuffer, "YOU NEED THE %s\n", - TextKeyMessages[lock - 1]); + 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/p_setup.c b/src/hexen/p_setup.c index 8940dd32..cd075651 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; - sprintf(lumpname, "MAP%02d", map); + 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 99ae73ae..06a4a6ff 100644 --- a/src/hexen/p_spec.c +++ b/src/hexen/p_spec.c @@ -428,7 +428,8 @@ static boolean CheckedLockedDoor(mobj_t * mo, byte lock) } if (!(mo->player->keys & (1 << (lock - 1)))) { - sprintf(LockedBuffer, "YOU NEED THE %s\n", TextKeyMessages[lock - 1]); + 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 a77e3a3b..b35c1f51 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; } - sprintf(text, "%s", c->name); + snprintf(text, sizeof(text), "%s", c->name); M_ForceUppercase(text); MN_DrTextA(text, xPos[x++], y); - sprintf(text, "%d", c->mo->type); + snprintf(text, sizeof(text), "%d", c->mo->type); MN_DrTextA(text, xPos[x++], y); - sprintf(text, "%d", c->mo->x >> FRACBITS); + snprintf(text, sizeof(text), "%d", c->mo->x >> FRACBITS); MN_DrTextA(text, xPos[x++], y); - sprintf(text, "%d", c->mo->y >> FRACBITS); + snprintf(text, sizeof(text), "%d", c->mo->y >> FRACBITS); MN_DrTextA(text, xPos[x++], y); - sprintf(text, "%d", (int) c->id); + snprintf(text, sizeof(text), "%d", (int) c->id); MN_DrTextA(text, xPos[x++], y); - sprintf(text, "%d", c->priority); + snprintf(text, sizeof(text), "%d", c->priority); MN_DrTextA(text, xPos[x++], y); - sprintf(text, "%d", c->distance); + 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; } - sprintf(mapName, "MAP%02d", map); + 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(); - sprintf(buffer, "%d MONSTERS KILLED\n", count); + snprintf(buffer, sizeof(buffer), "%d MONSTERS KILLED\n", count); P_SetMessage(player, buffer, true); } @@ -1857,11 +1857,12 @@ static void CheatVersionFunc(player_t * player, Cheat_t * cheat) static void CheatDebugFunc(player_t * player, Cheat_t * cheat) { char textBuffer[50]; - sprintf(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); + 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); } @@ -1896,7 +1897,8 @@ static void CheatScriptFunc3(player_t * player, Cheat_t * cheat) if (P_StartACS(script, 0, script_args, player->mo, NULL, 0)) { - sprintf(textBuffer, "RUNNING SCRIPT %.2d", script); + snprintf(textBuffer, sizeof(textBuffer), + "RUNNING SCRIPT %.2d", script); P_SetMessage(player, textBuffer, true); } } @@ -1928,7 +1930,7 @@ static void CheatTrackFunc1(player_t * player, Cheat_t * cheat) P_SetMessage(player, "ERROR INITIALIZING CD", true); } - sprintf(buffer, "ENTER DESIRED CD TRACK (%.2d - %.2d):\n", + snprintf(buffer, sizeof(buffer), "ENTER DESIRED CD TRACK (%.2d - %.2d):\n", I_CDMusFirstTrack(), I_CDMusLastTrack()); P_SetMessage(player, buffer, true); } @@ -1966,13 +1968,14 @@ static void CheatTrackFunc2(player_t * player, Cheat_t * cheat) if (!S_StartCustomCDTrack(track)) { - sprintf(buffer, "ERROR WHILE TRYING TO PLAY CD TRACK: %.2d\n", track); + 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 - sprintf(buffer, "PLAYING TRACK: %.2d\n", track); + 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 2802596b..35f5ec0b 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) { - sprintf(fileName, "%s%s.txt", sc_ScriptsDir, name); + 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 1a32ecd6..dd707398 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 - sprintf(fileName, "%shex6.hxs", SavePath); + 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 - sprintf(fileName, "%shex6%02d.hxs", SavePath, gamemap); + 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 - sprintf(fileName, "%shex6.hxs", SavePath); + 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; - sprintf(fileName, "%shex6%02d.hxs", SavePath, gamemap); + 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]; - sprintf(fileName, "%shex%d.hxs", SavePath, REBORN_SLOT); + 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 - sprintf(fileName, "%shex6%02d.hxs", SavePath, gamemap); + snprintf(fileName, sizeof(fileName), "%shex6%02d.hxs", SavePath, gamemap); // Load the file M_ReadFile(fileName, &SaveBuffer); @@ -3204,10 +3204,11 @@ static void ClearSaveSlot(int slot) for (i = 0; i < MAX_MAPS; i++) { - sprintf(fileName, "%shex%d%02d.hxs", SavePath, slot, i); + snprintf(fileName, sizeof(fileName), + "%shex%d%02d.hxs", SavePath, slot, i); remove(fileName); } - sprintf(fileName, "%shex%d.hxs", SavePath, slot); + snprintf(fileName, sizeof(fileName), "%shex%d.hxs", SavePath, slot); remove(fileName); } @@ -3227,17 +3228,21 @@ static void CopySaveSlot(int sourceSlot, int destSlot) for (i = 0; i < MAX_MAPS; i++) { - sprintf(sourceName, "%shex%d%02d.hxs", SavePath, sourceSlot, i); + snprintf(sourceName, sizeof(sourceName), + "%shex%d%02d.hxs", SavePath, sourceSlot, i); if (ExistingFile(sourceName)) { - sprintf(destName, "%shex%d%02d.hxs", SavePath, destSlot, i); + snprintf(destName, sizeof(destName), + "%shex%d%02d.hxs", SavePath, destSlot, i); CopyFile(sourceName, destName); } } - sprintf(sourceName, "%shex%d.hxs", SavePath, sourceSlot); + snprintf(sourceName, sizeof(sourceName), + "%shex%d.hxs", SavePath, sourceSlot); if (ExistingFile(sourceName)) { - sprintf(destName, "%shex%d.hxs", SavePath, destSlot); + snprintf(destName, sizeof(destName), + "%shex%d.hxs", SavePath, destSlot); CopyFile(sourceName, destName); } } |