Browse Source

Migrate snprintf to fmt (#4845)

* Migrate `app_fatal` from printf to libfmt
* Migrate snprintf to fmt
pull/4853/head
Gleb Mazovetskiy 4 years ago committed by GitHub
parent
commit
72660d9189
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 37
      Source/appfat.cpp
  2. 4
      Source/appfat.h
  3. 4
      Source/diablo.cpp
  4. 4
      Source/engine/demomode.cpp
  5. 8
      Source/engine/load_file.hpp
  6. 10
      Source/engine/render/scrollrt.cpp
  7. 8
      Source/init.cpp
  8. 2
      Source/inv.cpp
  9. 3
      Source/items.cpp
  10. 4
      Source/levels/themes.cpp
  11. 4
      Source/monster.cpp
  12. 4
      Source/mpq/mpq_writer.cpp
  13. 6
      Source/msg.cpp
  14. 6
      Source/multi.cpp
  15. 6
      Source/nthread.cpp
  16. 54
      Source/player.cpp
  17. 2
      Source/qol/monhealthbar.cpp
  18. 2
      Source/stores.cpp
  19. 8
      test/appfat_test.cpp

37
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

4
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

4
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()

4
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<uint8_t>(version);

8
Source/engine/load_file.hpp

@ -5,6 +5,8 @@
#include <cstdint>
#include <memory>
#include <fmt/core.h>
#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<byte *>(data), fileLen);
}
@ -91,7 +93,7 @@ std::unique_ptr<T[]> 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);

10
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 <fmt/compile.h>
#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<string_view::size_type>(end - buf) };
DrawString(out, str, Point { 8, 68 }, UiFlags::ColorRed);
}
/**

8
Source/init.cpp

@ -112,11 +112,7 @@ std::vector<std::string> 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<unsigned>(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);
}
}

2
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)

3
Source/items.cpp

@ -3241,8 +3241,9 @@ void CornerstoneSave()
PackItem(id, CornerStone.item, (CornerStone.item.dwBuff & CF_HELLFIRE) != 0);
const auto *buffer = reinterpret_cast<uint8_t *>(&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';
}

4
Source/levels/themes.cpp

@ -5,6 +5,8 @@
*/
#include "levels/themes.h"
#include <fmt/core.h>
#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<int>(themes[i].ttype)));
}
}
ApplyObjectLighting = false;

4
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<int>(monsterData.mMonstClass));
app_fatal(fmt::format("Unknown mMonstClass {}", static_cast<int>(monsterData.mMonstClass)));
}
void ActivateSpawn(int monsterId, Point position, Direction dir)

4
Source/mpq/mpq_writer.cpp

@ -6,6 +6,8 @@
#include <memory>
#include <type_traits>
#include <fmt/core.h>
#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;

6
Source/msg.cpp

@ -4,11 +4,11 @@
* Implementation of function for sending and reciving network messages.
*/
#include <climits>
#include <list>
#include <memory>
#include <unordered_map>
#include <fmt/format.h>
#include <list>
#include <unordered_map>
#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++;

6
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;

6
Source/nthread.cpp

@ -3,8 +3,10 @@
*
* Implementation of functions for managing game ticks.
*/
#include "nthread.h"
#include <fmt/core.h>
#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;

54
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;

2
Source/qol/monhealthbar.cpp

@ -117,7 +117,7 @@ void DrawMonsterHealthBar(const Surface &out)
return 150;
default:
app_fatal("Invalid monster class '%i'.", static_cast<int>(monsterClass));
app_fatal(fmt::format("Invalid monster class: {}", static_cast<int>(monsterClass)));
}
};

2
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<int>(stextshold)));
}
AddSText(0, 15, prompt, UiFlags::ColorWhite | UiFlags::AlignCenter, false);
AddSText(0, 18, _("Yes"), UiFlags::ColorWhite | UiFlags::AlignCenter, true);

8
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/");
}

Loading…
Cancel
Save