From 2c4e69c5c9ee956cc91cec557bcbaa7dddf78b1c Mon Sep 17 00:00:00 2001 From: obligaron Date: Sun, 16 Nov 2025 11:17:18 +0100 Subject: [PATCH] Fix MSVC warnings --- Source/loadsave.cpp | 6 +++--- Source/lua/modules/log.cpp | 15 ++++++++++----- Source/panels/console.cpp | 2 +- Source/utils/log.hpp | 9 +++++---- Source/utils/sdl2_to_1_2_backports.cpp | 16 ++++++++-------- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 29ac162dd..59d3eafd7 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -62,11 +62,11 @@ T SwapLE(T in) { switch (sizeof(T)) { case 2: - return Swap16LE(in); + return static_cast(Swap16LE(static_cast(in))); case 4: - return Swap32LE(in); + return static_cast(Swap32LE(static_cast(in))); case 8: - return Swap64LE(in); + return static_cast(Swap64LE(in)); default: return in; } diff --git a/Source/lua/modules/log.cpp b/Source/lua/modules/log.cpp index 42361adf0..7a743c424 100644 --- a/Source/lua/modules/log.cpp +++ b/Source/lua/modules/log.cpp @@ -49,15 +49,20 @@ void LuaLogMessage(LogPriority priority, std::string_view fmt, sol::variadic_arg } formatted = fmt::vformat(fmt, store); } +#if FMT_EXCEPTIONS FMT_CATCH(const fmt::format_error &e) { -#if FMT_EXCEPTIONS - // e.what() is undefined if exceptions are disabled, so we wrap the whole block + // e.what() is undefined if exceptions are disabled, so we wrap it // with an `FMT_EXCEPTIONS` check. - std::string error = StrCat("Format error, fmt: ", fmt, " error: ", e.what()); - SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "%s", error.c_str()); - return; + std::string error = e.what(); +#else + FMT_CATCH(const fmt::format_error) + { + std::string error = "unknown (FMT_EXCEPTIONS disabled)"; #endif + std::string fullError = StrCat("Format error, fmt: ", fmt, " error: ", error); + SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "%s", fullError.c_str()); + return; } SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, static_cast(priority), "%s", formatted.c_str()); } diff --git a/Source/panels/console.cpp b/Source/panels/console.cpp index f6716fd5a..2b6ceabe5 100644 --- a/Source/panels/console.cpp +++ b/Source/panels/console.cpp @@ -591,7 +591,7 @@ void DrawConsole(const Surface &out) if (FirstRender) { SDL_Rect sdlInputRect = MakeSdlRect(InputRect); - SDL_SetTextInputArea(ghMainWnd, &sdlInputRect, ConsoleInputState.cursorPosition()); + SDL_SetTextInputArea(ghMainWnd, &sdlInputRect, static_cast(ConsoleInputState.cursorPosition())); SDLC_StartTextInput(ghMainWnd); FirstRender = false; if (ConsoleLines.empty()) { diff --git a/Source/utils/log.hpp b/Source/utils/log.hpp index cfacf1a7a..1ada28c1d 100644 --- a/Source/utils/log.hpp +++ b/Source/utils/log.hpp @@ -55,15 +55,16 @@ std::string format(std::string_view fmt, Args &&...args) { return fmt::format(fmt::runtime(fmt), std::forward(args)...); } +#if FMT_EXCEPTIONS FMT_CATCH(const fmt::format_error &e) { - std::string error; -#if FMT_EXCEPTIONS // e.what() is undefined if exceptions are disabled, so we wrap it // with an `FMT_EXCEPTIONS` check. - error = e.what(); + std::string error = e.what(); #else - error = "unknown (FMT_EXCEPTIONS disabled)"; + FMT_CATCH(const fmt::format_error) + { + std::string error = "unknown (FMT_EXCEPTIONS disabled)"; #endif std::string fullError = StrCat("Format error, fmt: ", fmt, " error: ", error); SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "%s", error.c_str()); diff --git a/Source/utils/sdl2_to_1_2_backports.cpp b/Source/utils/sdl2_to_1_2_backports.cpp index 14414a695..c3025d64b 100644 --- a/Source/utils/sdl2_to_1_2_backports.cpp +++ b/Source/utils/sdl2_to_1_2_backports.cpp @@ -384,8 +384,8 @@ int SDL_BlitScaled(SDL_Surface *src, SDL_Rect *srcrect, if (NULL == dstrect) { dst_x0 = 0; dst_y0 = 0; - dst_x1 = dst_w - 1; - dst_y1 = dst_h - 1; + dst_x1 = static_cast(dst_w - 1); + dst_y1 = static_cast(dst_h - 1); } else { dst_x0 = dstrect->x; dst_y0 = dstrect->y; @@ -396,8 +396,8 @@ int SDL_BlitScaled(SDL_Surface *src, SDL_Rect *srcrect, if (NULL == srcrect) { src_x0 = 0; src_y0 = 0; - src_x1 = src_w - 1; - src_y1 = src_h - 1; + src_x1 = static_cast(src_w - 1); + src_y1 = static_cast(src_h - 1); } else { src_x0 = srcrect->x; src_y0 = srcrect->y; @@ -413,7 +413,7 @@ int SDL_BlitScaled(SDL_Surface *src, SDL_Rect *srcrect, if (src_x1 >= src->w) { dst_x1 -= (src_x1 - src->w + 1) * scaling_w; - src_x1 = src->w - 1; + src_x1 = static_cast(src->w - 1); } if (src_y0 < 0) { @@ -423,7 +423,7 @@ int SDL_BlitScaled(SDL_Surface *src, SDL_Rect *srcrect, if (src_y1 >= src->h) { dst_y1 -= (src_y1 - src->h + 1) * scaling_h; - src_y1 = src->h - 1; + src_y1 = static_cast(src->h - 1); } } @@ -442,7 +442,7 @@ int SDL_BlitScaled(SDL_Surface *src, SDL_Rect *srcrect, if (dst_x1 >= dst->clip_rect.w) { src_x1 -= (dst_x1 - dst->clip_rect.w + 1) / scaling_w; - dst_x1 = dst->clip_rect.w - 1; + dst_x1 = static_cast(dst->clip_rect.w - 1); } if (dst_y0 < 0) { @@ -452,7 +452,7 @@ int SDL_BlitScaled(SDL_Surface *src, SDL_Rect *srcrect, if (dst_y1 >= dst->clip_rect.h) { src_y1 -= (dst_y1 - dst->clip_rect.h + 1) / scaling_h; - dst_y1 = dst->clip_rect.h - 1; + dst_y1 = static_cast(dst->clip_rect.h - 1); } /* Translate back to surface coordinates */