From 72660d9189ad97ecc6c5270c86599578dc369324 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sat, 2 Jul 2022 01:36:17 +0100 Subject: [PATCH] Migrate snprintf to fmt (#4845) * Migrate `app_fatal` from printf to libfmt * Migrate snprintf to fmt --- Source/appfat.cpp | 37 +++------------------ Source/appfat.h | 4 +-- Source/diablo.cpp | 4 +-- Source/engine/demomode.cpp | 4 +-- Source/engine/load_file.hpp | 8 +++-- Source/engine/render/scrollrt.cpp | 10 ++++-- Source/init.cpp | 8 ++--- Source/inv.cpp | 2 +- Source/items.cpp | 3 +- Source/levels/themes.cpp | 4 ++- Source/monster.cpp | 4 +-- Source/mpq/mpq_writer.cpp | 4 ++- Source/msg.cpp | 6 ++-- Source/multi.cpp | 6 ++-- Source/nthread.cpp | 6 ++-- Source/player.cpp | 54 +++++++++++++++---------------- Source/qol/monhealthbar.cpp | 2 +- Source/stores.cpp | 2 +- test/appfat_test.cpp | 8 ++--- 19 files changed, 77 insertions(+), 99 deletions(-) diff --git a/Source/appfat.cpp b/Source/appfat.cpp index 98c379a98..b9a1f7f7f 100644 --- a/Source/appfat.cpp +++ b/Source/appfat.cpp @@ -24,20 +24,6 @@ bool Terminating = false; /** Thread id of the last callee to FreeDlg(). */ SDL_threadID CleanupThreadId; -/** - * @brief Displays an error message box based on the given format string and variable argument list. - * @param pszFmt Error message format - * @param va Additional parameters for message format - */ -void MsgBox(const char *pszFmt, va_list va) -{ - char text[256]; - - vsnprintf(text, sizeof(text), pszFmt, va); - - UiErrorOkDialog(_("Error"), text); -} - /** * @brief Cleans up after a fatal application error. */ @@ -66,25 +52,10 @@ void app_fatal(string_view str) diablo_quit(1); } -void app_fatal(const char *pszFmt, ...) -{ - va_list va; - - va_start(va, pszFmt); - FreeDlg(); - - if (pszFmt != nullptr) - MsgBox(pszFmt, va); - - va_end(va); - - diablo_quit(1); -} - #ifdef _DEBUG void assert_fail(int nLineNo, const char *pszFile, const char *pszFail) { - app_fatal("assertion failed (%s:%i)\n%s", pszFile, nLineNo, pszFail); + app_fatal(fmt::format("assertion failed ({}:{})\n{}", pszFile, nLineNo, pszFail)); } #endif @@ -95,7 +66,7 @@ void ErrDlg(const char *title, string_view error, string_view logFilePath, int l std::string text = fmt::format(fmt::runtime(_(/* TRANSLATORS: Error message that displays relevant information for bug report */ "{:s}\n\nThe error occurred at: {:s} line {:d}")), error, logFilePath, logLineNr); UiErrorOkDialog(title, text); - app_fatal(nullptr); + diablo_quit(1); } void InsertCDDlg(string_view archiveName) @@ -107,7 +78,7 @@ void InsertCDDlg(string_view archiveName) archiveName); UiErrorOkDialog(_("Data File Error"), text); - app_fatal(nullptr); + diablo_quit(1); } void DirErrorDlg(string_view error) @@ -115,7 +86,7 @@ void DirErrorDlg(string_view error) std::string text = fmt::format(fmt::runtime(_(/* TRANSLATORS: Error when Program is not allowed to write data */ "Unable to write to location:\n{:s}")), error); UiErrorOkDialog(_("Read-Only Directory Error"), text); - app_fatal(nullptr); + diablo_quit(1); } } // namespace devilution diff --git a/Source/appfat.h b/Source/appfat.h index 0b51b1f2a..34e90e77e 100644 --- a/Source/appfat.h +++ b/Source/appfat.h @@ -27,10 +27,8 @@ namespace devilution { /** * @brief Terminates the game and displays an error message box. - * @param pszFmt Optional error message. - * @param ... (see printf) + * @param str Error message. */ -[[noreturn]] void app_fatal(const char *pszFmt, ...) DVL_PRINTF_ATTRIBUTE(1, 2); [[noreturn]] void app_fatal(string_view str); #ifdef _DEBUG diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 262c1bec3..de57e8ee9 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -991,8 +991,8 @@ void DiabloInitScreen() void SetApplicationVersions() { - snprintf(gszProductName, sizeof(gszProductName) / sizeof(char), "%s v%s", PROJECT_NAME, PROJECT_VERSION); - CopyUtf8(gszVersionNumber, fmt::format(fmt::runtime(_("version {:s}")), PROJECT_VERSION), sizeof(gszVersionNumber) / sizeof(char)); + *fmt::format_to_n(gszProductName, sizeof(gszProductName) - 1, "{} v{}", PROJECT_NAME, PROJECT_VERSION).out = '\0'; + CopyUtf8(gszVersionNumber, fmt::format(fmt::runtime(_("version {:s}")), PROJECT_VERSION), sizeof(gszVersionNumber)); } void DiabloInit() diff --git a/Source/engine/demomode.cpp b/Source/engine/demomode.cpp index 688769dd4..3d7079af9 100644 --- a/Source/engine/demomode.cpp +++ b/Source/engine/demomode.cpp @@ -75,7 +75,7 @@ bool LoadDemoMessages(int i) { std::ifstream demofile; char demoFilename[16]; - snprintf(demoFilename, 15, "demo_%d.dmo", i); + *fmt::format_to_n(demoFilename, 15, "demo_{}.dmo", i).out = '\0'; demofile.open(paths::PrefPath() + demoFilename, std::fstream::binary); if (!demofile.is_open()) { return false; @@ -269,7 +269,7 @@ void NotifyGameLoopStart() { if (IsRecording()) { char demoFilename[16]; - snprintf(demoFilename, 15, "demo_%d.dmo", RecordNumber); + *fmt::format_to_n(demoFilename, 15, "demo_{}.dmo", RecordNumber).out = '\0'; DemoRecording.open(paths::PrefPath() + demoFilename, std::fstream::trunc | std::fstream::binary); constexpr uint8_t version = 0; WriteToDemo(version); diff --git a/Source/engine/load_file.hpp b/Source/engine/load_file.hpp index 67a894c70..db9987e39 100644 --- a/Source/engine/load_file.hpp +++ b/Source/engine/load_file.hpp @@ -5,6 +5,8 @@ #include #include +#include + #include "appfat.h" #include "diablo.h" #include "engine/assets.hpp" @@ -20,7 +22,7 @@ public: handle_ = OpenAsset(path); if (handle_ == nullptr) { if (!gbQuietMode) { - app_fatal("Failed to open file:\n%s\n\n%s", path, SDL_GetError()); + app_fatal(fmt::format("Failed to open file:\n{}\n\n{}", path, SDL_GetError())); } } } @@ -58,7 +60,7 @@ void LoadFileInMem(const char *path, T *data) return; const std::size_t fileLen = file.Size(); if ((fileLen % sizeof(T)) != 0) - app_fatal("File size does not align with type\n%s", path); + app_fatal(fmt::format("File size does not align with type\n{}", path)); file.Read(reinterpret_cast(data), fileLen); } @@ -91,7 +93,7 @@ std::unique_ptr LoadFileInMem(const char *path, std::size_t *numRead = null return nullptr; const std::size_t fileLen = file.Size(); if ((fileLen % sizeof(T)) != 0) - app_fatal("File size does not align with type\n%s", path); + app_fatal(fmt::format("File size does not align with type\n{}", path)); if (numRead != nullptr) *numRead = fileLen / sizeof(T); diff --git a/Source/engine/render/scrollrt.cpp b/Source/engine/render/scrollrt.cpp index b970f1f10..a87a5408f 100644 --- a/Source/engine/render/scrollrt.cpp +++ b/Source/engine/render/scrollrt.cpp @@ -3,6 +3,9 @@ * * Implementation of functionality for rendering the dungeons, monsters and calling other render routines. */ +#include "engine/render/scrollrt.h" + +#include #include "DiabloUI/ui_flags.hpp" #include "automap.h" @@ -1319,7 +1322,7 @@ void DrawView(const Surface &out, Point startPosition) */ void DrawFPS(const Surface &out) { - char string[12]; + char buf[12]; if (!frameflag || !gbActive) { return; @@ -1333,8 +1336,9 @@ void DrawFPS(const Surface &out) framerate = 1000 * frameend / frames; frameend = 0; } - snprintf(string, 12, "%i FPS", framerate); - DrawString(out, string, Point { 8, 68 }, UiFlags::ColorRed); + const char *end = fmt::format_to_n(buf, sizeof(buf), FMT_COMPILE("{} FPS"), framerate).out; + string_view str { buf, static_cast(end - buf) }; + DrawString(out, str, Point { 8, 68 }, UiFlags::ColorRed); } /** diff --git a/Source/init.cpp b/Source/init.cpp index 2ec3fbcc2..887a725d8 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -112,11 +112,7 @@ std::vector GetMPQSearchPaths() std::string message; for (std::size_t i = 0; i < paths.size(); ++i) { - char prefix[32]; - std::snprintf(prefix, sizeof(prefix), "\n%6u. '", static_cast(i + 1)); - message.append(prefix); - message.append(paths[i]); - message += '\''; + message.append(fmt::format("\n{:6d}. '{}'", i + 1, paths[i])); } LogVerbose("MPQ search paths:{}", message); } @@ -213,7 +209,7 @@ void LoadGameArchives() if (gbIsHellfire && (!hfmonk_mpq || !hfmusic_mpq || !hfvoice_mpq)) { UiErrorOkDialog(_("Some Hellfire MPQs are missing"), _("Not all Hellfire MPQs were found.\nPlease copy all the hf*.mpq files.")); - app_fatal(nullptr); + diablo_quit(1); } } diff --git a/Source/inv.cpp b/Source/inv.cpp index 0bbb7ad4a..458c0e5ac 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -1349,7 +1349,7 @@ bool AutoPlaceItemInInventory(Player &player, const Item &item, bool persistItem return false; } - app_fatal("Unknown item size: %ix%i", itemSize.width, itemSize.height); + app_fatal(fmt::format("Unknown item size: {}x{}", itemSize.width, itemSize.height)); } bool AutoPlaceItemInInventorySlot(Player &player, int slotIndex, const Item &item, bool persistItem) diff --git a/Source/items.cpp b/Source/items.cpp index d78447895..c9e88003e 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -3241,8 +3241,9 @@ void CornerstoneSave() PackItem(id, CornerStone.item, (CornerStone.item.dwBuff & CF_HELLFIRE) != 0); const auto *buffer = reinterpret_cast(&id); for (size_t i = 0; i < sizeof(ItemPack); i++) { - snprintf(&sgOptions.Hellfire.szItem[i * 2], 3, "%02hhX", buffer[i]); + fmt::format_to(&sgOptions.Hellfire.szItem[i * 2], FMT_COMPILE("{:02X}"), buffer[i]); } + sgOptions.Hellfire.szItem[sizeof(sgOptions.Hellfire.szItem) - 1] = '\0'; } else { sgOptions.Hellfire.szItem[0] = '\0'; } diff --git a/Source/levels/themes.cpp b/Source/levels/themes.cpp index 4ce00e285..c987306cf 100644 --- a/Source/levels/themes.cpp +++ b/Source/levels/themes.cpp @@ -5,6 +5,8 @@ */ #include "levels/themes.h" +#include + #include "engine/path.h" #include "engine/points_in_rectangle_range.hpp" #include "engine/random.hpp" @@ -1024,7 +1026,7 @@ void CreateThemeRooms() Theme_WeaponRack(i); break; case THEME_NONE: - app_fatal("Unknown theme type: %i", themes[i].ttype); + app_fatal(fmt::format("Unknown theme type: {}", static_cast(themes[i].ttype))); } } ApplyObjectLighting = false; diff --git a/Source/monster.cpp b/Source/monster.cpp index f617c0a5e..de9fb2bca 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -1634,7 +1634,7 @@ bool MonsterTalk(Monster &monster) monster._mFlags |= MFLAG_QUEST_COMPLETE; } if (Quests[Q_LTBANNER]._qvar1 < 2) { - app_fatal("SS Talk = %i, Flags = %i", monster.mtalkmsg, monster._mFlags); + app_fatal(fmt::format("SS Talk = {}, Flags = {}", monster.mtalkmsg, monster._mFlags)); } } if (monster._uniqtype - 1 == UMT_LACHDAN) { @@ -3319,7 +3319,7 @@ string_view GetMonsterTypeText(const MonsterData &monsterData) return _("Undead"); } - app_fatal("Unknown mMonstClass %i", static_cast(monsterData.mMonstClass)); + app_fatal(fmt::format("Unknown mMonstClass {}", static_cast(monsterData.mMonstClass))); } void ActivateSpawn(int monsterId, Point position, Direction dir) diff --git a/Source/mpq/mpq_writer.cpp b/Source/mpq/mpq_writer.cpp index 16fd7c028..bc1bdf585 100644 --- a/Source/mpq/mpq_writer.cpp +++ b/Source/mpq/mpq_writer.cpp @@ -6,6 +6,8 @@ #include #include +#include + #include "appfat.h" #include "encrypt.h" #include "engine.h" @@ -325,7 +327,7 @@ MpqBlockEntry *MpqWriter::AddFile(const char *filename, MpqBlockEntry *block, ui uint32_t h2 = Hash(filename, 1); uint32_t h3 = Hash(filename, 2); if (GetHashIndex(h1, h2, h3) != HashEntryNotFound) - app_fatal("Hash collision between \"%s\" and existing file\n", filename); + app_fatal(fmt::format("Hash collision between \"{}\" and existing file\n", filename)); unsigned int hIdx = h1 & 0x7FF; bool hasSpace = false; diff --git a/Source/msg.cpp b/Source/msg.cpp index 8f7fa932a..ac33e926f 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -4,11 +4,11 @@ * Implementation of function for sending and reciving network messages. */ #include +#include #include +#include #include -#include -#include #include "DiabloUI/diabloui.h" #include "automap.h" @@ -446,7 +446,7 @@ void DeltaImportData(_cmd_id cmd, DWORD recvOffset) src += DeltaImportObject(src, deltaLevel.object); DeltaImportMonster(src, deltaLevel.monster); } else { - app_fatal("Unkown network message type: %i", cmd); + app_fatal(fmt::format("Unkown network message type: {}", cmd)); } sgbDeltaChunks++; diff --git a/Source/multi.cpp b/Source/multi.cpp index 7a270436e..9ad23b1dc 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -372,7 +372,7 @@ void HandleEvents(_SNETEVENT *pEvt) case EVENT_TYPE_PLAYER_CREATE_GAME: { auto *gameData = (GameData *)pEvt->data; if (gameData->size != sizeof(GameData)) - app_fatal("Invalid size of game data: %i", gameData->size); + app_fatal(fmt::format("Invalid size of game data: {}", gameData->size)); sgGameInitInfo = *gameData; sgbPlayerTurnBitTbl[pEvt->playerid] = true; break; @@ -405,7 +405,7 @@ void EventHandler(bool add) for (auto eventType : EventTypes) { if (add) { if (!SNetRegisterEventHandler(eventType, HandleEvents)) { - app_fatal("SNetRegisterEventHandler:\n%s", SDL_GetError()); + app_fatal(fmt::format("SNetRegisterEventHandler:\n{}", SDL_GetError())); } } else { SNetUnregisterEventHandler(eventType); @@ -421,7 +421,7 @@ bool InitSingle(GameData *gameData) int unused = 0; if (!SNetCreateGame("local", "local", (char *)&sgGameInitInfo, sizeof(sgGameInitInfo), &unused)) { - app_fatal("SNetCreateGame1:\n%s", SDL_GetError()); + app_fatal(fmt::format("SNetCreateGame1:\n{}", SDL_GetError())); } MyPlayerId = 0; diff --git a/Source/nthread.cpp b/Source/nthread.cpp index 2126ee94a..18a119ba0 100644 --- a/Source/nthread.cpp +++ b/Source/nthread.cpp @@ -3,8 +3,10 @@ * * Implementation of functions for managing game ticks. */ - #include "nthread.h" + +#include + #include "diablo.h" #include "engine/demomode.h" #include "gmenu.h" @@ -68,7 +70,7 @@ void nthread_terminate_game(const char *pszFcn) return; } if (sErr != STORM_ERROR_GAME_TERMINATED && sErr != STORM_ERROR_NOT_IN_GAME) { - app_fatal("%s:\n%s", pszFcn, SDL_GetError()); + app_fatal(fmt::format("{}:\n{}", pszFcn, SDL_GetError())); } gbGameDestroyed = true; diff --git a/Source/player.cpp b/Source/player.cpp index cc5d4dc46..fbcff9072 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -392,7 +392,7 @@ void ClearStateVariables(Player &player) void StartWalkStand(int pnum) { if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("StartWalkStand: illegal player %i", pnum); + app_fatal(fmt::format("StartWalkStand: illegal player {}", pnum)); } Player &player = Players[pnum]; @@ -436,7 +436,7 @@ void ChangeOffset(Player &player) void StartAttack(int pnum, Direction d) { if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("StartAttack: illegal player %i", pnum); + app_fatal(fmt::format("StartAttack: illegal player {}", pnum)); } Player &player = Players[pnum]; @@ -468,7 +468,7 @@ void StartAttack(int pnum, Direction d) void StartRangeAttack(int pnum, Direction d, WorldTileCoord cx, WorldTileCoord cy) { if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("StartRangeAttack: illegal player %i", pnum); + app_fatal(fmt::format("StartRangeAttack: illegal player {}", pnum)); } Player &player = Players[pnum]; @@ -510,7 +510,7 @@ player_graphic GetPlayerGraphicForSpell(spell_id spellId) void StartSpell(int pnum, Direction d, WorldTileCoord cx, WorldTileCoord cy) { if ((DWORD)pnum >= MAX_PLRS) - app_fatal("StartSpell: illegal player %i", pnum); + app_fatal(fmt::format("StartSpell: illegal player {}", pnum)); Player &player = Players[pnum]; if (player._pInvincible && player._pHitPoints == 0 && pnum == MyPlayerId) { @@ -652,7 +652,7 @@ void InitLevelChange(int pnum) bool DoWalk(int pnum, int variant) { if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("PM_DoWalk: illegal player %i", pnum); + app_fatal(fmt::format("PM_DoWalk: illegal player {}", pnum)); } Player &player = Players[pnum]; @@ -805,12 +805,12 @@ bool PlrHitMonst(int pnum, int m, bool adjacentDamage = false) int hper = 0; if ((DWORD)m >= MaxMonsters) { - app_fatal("PlrHitMonst: illegal monster %i", m); + app_fatal(fmt::format("PlrHitMonst: illegal monster {}", m)); } auto &monster = Monsters[m]; if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("PlrHitMonst: illegal player %i", pnum); + app_fatal(fmt::format("PlrHitMonst: illegal player {}", pnum)); } Player &player = Players[pnum]; @@ -988,7 +988,7 @@ bool PlrHitMonst(int pnum, int m, bool adjacentDamage = false) bool PlrHitPlr(Player &attacker, int8_t p) { if ((DWORD)p >= MAX_PLRS) { - app_fatal("PlrHitPlr: illegal target player %i", p); + app_fatal(fmt::format("PlrHitPlr: illegal target player {}", p)); } Player &target = Players[p]; @@ -1068,7 +1068,7 @@ bool PlrHitObj(int pnum, Object &targetObject) bool DoAttack(int pnum) { if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("PM_DoAttack: illegal player %i", pnum); + app_fatal(fmt::format("PM_DoAttack: illegal player {}", pnum)); } Player &player = Players[pnum]; @@ -1177,7 +1177,7 @@ bool DoAttack(int pnum) bool DoRangeAttack(int pnum) { if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("PM_DoRangeAttack: illegal player %i", pnum); + app_fatal(fmt::format("PM_DoRangeAttack: illegal player {}", pnum)); } Player &player = Players[pnum]; @@ -1277,7 +1277,7 @@ void DamageParryItem(Player &player) bool DoBlock(int pnum) { if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("PM_DoBlock: illegal player %i", pnum); + app_fatal(fmt::format("PM_DoBlock: illegal player {}", pnum)); } Player &player = Players[pnum]; @@ -1338,7 +1338,7 @@ void DamageArmor(Player &player) bool DoSpell(int pnum) { if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("PM_DoSpell: illegal player %i", pnum); + app_fatal(fmt::format("PM_DoSpell: illegal player {}", pnum)); } Player &player = Players[pnum]; @@ -1369,7 +1369,7 @@ bool DoSpell(int pnum) bool DoGotHit(int pnum) { if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("PM_DoGotHit: illegal player %i", pnum); + app_fatal(fmt::format("PM_DoGotHit: illegal player {}", pnum)); } Player &player = Players[pnum]; @@ -1417,7 +1417,7 @@ bool IsPlayerAdjacentToObject(Player &player, Object &object) void CheckNewPath(int pnum, bool pmWillBeCalled) { if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("CheckNewPath: illegal player %i", pnum); + app_fatal(fmt::format("CheckNewPath: illegal player {}", pnum)); } Player &player = Players[pnum]; @@ -1755,7 +1755,7 @@ bool PlrDeathModeOK(Player &player) void ValidatePlayer() { if ((DWORD)MyPlayerId >= MAX_PLRS) { - app_fatal("ValidatePlayer: illegal player %i", MyPlayerId); + app_fatal(fmt::format("ValidatePlayer: illegal player {}", MyPlayerId)); } Player &myPlayer = *MyPlayer; @@ -2802,7 +2802,7 @@ void InitPlayer(Player &player, bool firstTime) void InitMultiView() { if ((DWORD)MyPlayerId >= MAX_PLRS) { - app_fatal("InitPlayer: illegal player %i", MyPlayerId); + app_fatal(fmt::format("InitPlayer: illegal player {}", MyPlayerId)); } Player &myPlayer = *MyPlayer; @@ -2856,7 +2856,7 @@ void FixPlayerLocation(Player &player, Direction bDir) void StartStand(int pnum, Direction dir) { if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("StartStand: illegal player %i", pnum); + app_fatal(fmt::format("StartStand: illegal player {}", pnum)); } Player &player = Players[pnum]; @@ -2876,7 +2876,7 @@ void StartStand(int pnum, Direction dir) void StartPlrBlock(int pnum, Direction dir) { if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("StartPlrBlock: illegal player %i", pnum); + app_fatal(fmt::format("StartPlrBlock: illegal player {}", pnum)); } Player &player = Players[pnum]; @@ -2902,7 +2902,7 @@ void StartPlrBlock(int pnum, Direction dir) void FixPlrWalkTags(int pnum) { if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("FixPlrWalkTags: illegal player %i", pnum); + app_fatal(fmt::format("FixPlrWalkTags: illegal player {}", pnum)); } Player &player = Players[pnum]; @@ -2934,7 +2934,7 @@ void RemovePlrFromMap(int pnum) void StartPlrHit(int pnum, int dam, bool forcehit) { if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("StartPlrHit: illegal player %i", pnum); + app_fatal(fmt::format("StartPlrHit: illegal player {}", pnum)); } Player &player = Players[pnum]; @@ -2986,7 +2986,7 @@ void StartPlayerKill(int pnum, int earflag) { if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("StartPlayerKill: illegal player %i", pnum); + app_fatal(fmt::format("StartPlayerKill: illegal player {}", pnum)); } Player &player = Players[pnum]; @@ -3194,7 +3194,7 @@ StartNewLvl(int pnum, interface_mode fom, int lvl) InitLevelChange(pnum); if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("StartNewLvl: illegal player %i", pnum); + app_fatal(fmt::format("StartNewLvl: illegal player {}", pnum)); } Player &player = Players[pnum]; Player &myPlayer = *MyPlayer; @@ -3234,7 +3234,7 @@ void RestartTownLvl(int pnum) { InitLevelChange(pnum); if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("RestartTownLvl: illegal player %i", pnum); + app_fatal(fmt::format("RestartTownLvl: illegal player {}", pnum)); } Player &player = Players[pnum]; @@ -3283,7 +3283,7 @@ void StartWarpLvl(int pnum, int pidx) void ProcessPlayers() { if ((DWORD)MyPlayerId >= MAX_PLRS) { - app_fatal("ProcessPlayers: illegal player %i", MyPlayerId); + app_fatal(fmt::format("ProcessPlayers: illegal player {}", MyPlayerId)); } Player &myPlayer = *MyPlayer; @@ -3451,7 +3451,7 @@ void CheckPlrSpell(bool isShiftHeld, spell_id spellID, spell_type spellType) int sl; if ((DWORD)MyPlayerId >= MAX_PLRS) { - app_fatal("CheckPlrSpell: illegal player %i", MyPlayerId); + app_fatal(fmt::format("CheckPlrSpell: illegal player {}", MyPlayerId)); } Player &myPlayer = *MyPlayer; @@ -3630,7 +3630,7 @@ void SyncInitPlrPos(int pnum) void SyncInitPlr(int pnum) { if ((DWORD)pnum >= MAX_PLRS) { - app_fatal("SyncInitPlr: illegal player %i", pnum); + app_fatal(fmt::format("SyncInitPlr: illegal player {}", pnum)); } Player &player = Players[pnum]; @@ -3811,7 +3811,7 @@ enum { void PlayDungMsgs() { if ((DWORD)MyPlayerId >= MAX_PLRS) { - app_fatal("PlayDungMsgs: illegal player %i", MyPlayerId); + app_fatal(fmt::format("PlayDungMsgs: illegal player {}", MyPlayerId)); } Player &myPlayer = *MyPlayer; diff --git a/Source/qol/monhealthbar.cpp b/Source/qol/monhealthbar.cpp index 0c3b5870d..f96a573f1 100644 --- a/Source/qol/monhealthbar.cpp +++ b/Source/qol/monhealthbar.cpp @@ -117,7 +117,7 @@ void DrawMonsterHealthBar(const Surface &out) return 150; default: - app_fatal("Invalid monster class '%i'.", static_cast(monsterClass)); + app_fatal(fmt::format("Invalid monster class: {}", static_cast(monsterClass))); } }; diff --git a/Source/stores.cpp b/Source/stores.cpp index b7c811a10..d29ad75c4 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -1022,7 +1022,7 @@ void StoreConfirm(Item &item) prompt = _("Are you sure you want to repair this item?"); break; default: - app_fatal("Unknown store dialog %i", stextshold); + app_fatal(fmt::format("Unknown store dialog {}", static_cast(stextshold))); } AddSText(0, 15, prompt, UiFlags::ColorWhite | UiFlags::AlignCenter, false); AddSText(0, 18, _("Yes"), UiFlags::ColorWhite | UiFlags::AlignCenter, true); diff --git a/test/appfat_test.cpp b/test/appfat_test.cpp index f4fad54c9..5f39d39db 100644 --- a/test/appfat_test.cpp +++ b/test/appfat_test.cpp @@ -5,22 +5,22 @@ using namespace devilution; -TEST(Appfat, app_fatal) +TEST(AppfatTest, app_fatal) { EXPECT_EXIT(app_fatal("test"), ::testing::ExitedWithCode(1), "test"); } -TEST(Appfat, ErrDlg) +TEST(AppfatTest, ErrDlg) { EXPECT_EXIT(ErrDlg("Title", "Unknown error", "appfat.cpp", 7), ::testing::ExitedWithCode(1), "Unknown error\n\nThe error occurred at: appfat.cpp line 7"); } -TEST(Appfat, InsertCDDlg) +TEST(AppfatTest, InsertCDDlg) { EXPECT_EXIT(InsertCDDlg("diabdat.mpq"), ::testing::ExitedWithCode(1), "diabdat.mpq"); } -TEST(Appfat, DirErrorDlg) +TEST(AppfatTest, DirErrorDlg) { EXPECT_EXIT(DirErrorDlg("/"), ::testing::ExitedWithCode(1), "Unable to write to location:\n/"); }