From 808ac0c5571adbfed06e386560b541f7260aba7d Mon Sep 17 00:00:00 2001 From: GEEKiDoS Date: Fri, 19 Sep 2025 12:57:38 +0800 Subject: [PATCH] Fix msvc compiler warnings (#374) To be noticed I edited thirdparty header for fmt library (#373), idk if it is acceptable --- src/spice2x/CMakeLists.txt | 19 +++++++++++++++++++ src/spice2x/acioemu/icca.cpp | 2 +- src/spice2x/external/fmt/include/fmt/core.h | 4 ++++ src/spice2x/games/ccj/trackball.cpp | 2 +- src/spice2x/games/otoca/p4io.cpp | 2 +- src/spice2x/hooks/networkhook.cpp | 4 ++++ src/spice2x/launcher/options.cpp | 2 +- src/spice2x/misc/extdev.cpp | 2 +- src/spice2x/util/detour.cpp | 4 ++++ 9 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/spice2x/CMakeLists.txt b/src/spice2x/CMakeLists.txt index 4de36a6..e61bcc9 100644 --- a/src/spice2x/CMakeLists.txt +++ b/src/spice2x/CMakeLists.txt @@ -80,6 +80,25 @@ if(MSVC) # enable COMDAT folding for even smaller release builds add_link_options("$<$:/OPT:ICF>") + + # always use UTF-8 (fix 4819) + add_compile_options("/utf-8") + + # spectre mitigation warning + add_compile_options("/wd5045") + + # implicit type convert warnings + add_compile_options("/wd4244") + add_compile_options("/wd4267") + add_compile_options("/wd4305") + + # unreferenced local variable + add_compile_options("/wd4101") + + # warning in winbase.h?? + add_compile_options("/wd5039") + + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # disable warnings about using non _s variants like strncpy add_compile_definitions(_CRT_SECURE_NO_WARNINGS) diff --git a/src/spice2x/acioemu/icca.cpp b/src/spice2x/acioemu/icca.cpp index b72efaf..56fce06 100644 --- a/src/spice2x/acioemu/icca.cpp +++ b/src/spice2x/acioemu/icca.cpp @@ -373,7 +373,7 @@ void ICCADevice::update_card(int unit) { bool kb_insert_press = false; // eamio keypress - kb_insert_press |= eamuse_get_keypad_state((size_t) unit) & (1 << EAM_IO_INSERT); + kb_insert_press |= static_cast(eamuse_get_keypad_state((size_t) unit) & (1 << EAM_IO_INSERT)); // check for card if (this->cards[unit] == nullptr && (eamuse_card_insert_consume(this->node_count, unit) || kb_insert_press)) { diff --git a/src/spice2x/external/fmt/include/fmt/core.h b/src/spice2x/external/fmt/include/fmt/core.h index a4facb3..cacd858 100644 --- a/src/spice2x/external/fmt/include/fmt/core.h +++ b/src/spice2x/external/fmt/include/fmt/core.h @@ -1527,8 +1527,10 @@ FMT_CONSTEXPR auto make_arg(const T& value) -> basic_format_arg { return arg; } +#ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdangling-reference" +#endif // The type template parameter is there to avoid an ODR violation when using // a fallback formatter in one translation unit and an implicit conversion in @@ -1544,7 +1546,9 @@ FMT_CONSTEXPR FMT_INLINE auto make_arg(const T& val) -> value { return arg; } +#ifdef __GNUC__ #pragma GCC diagnostic pop +#endif template diff --git a/src/spice2x/games/ccj/trackball.cpp b/src/spice2x/games/ccj/trackball.cpp index 6a77c53..5485f94 100644 --- a/src/spice2x/games/ccj/trackball.cpp +++ b/src/spice2x/games/ccj/trackball.cpp @@ -14,7 +14,7 @@ namespace games::ccj { bool MOUSE_TRACKBALL_USE_TOGGLE = false; uint8_t TRACKBALL_SENSITIVITY = 10; - static HANDLE fakeHandle = (HANDLE)0xDEADBEEF; + static HANDLE fakeHandle = (HANDLE)0xDEADBEEFull; static HWND hWnd = nullptr; static WNDPROC wndProc = nullptr; static std::thread *tbThread = nullptr; diff --git a/src/spice2x/games/otoca/p4io.cpp b/src/spice2x/games/otoca/p4io.cpp index dcff583..5485de9 100644 --- a/src/spice2x/games/otoca/p4io.cpp +++ b/src/spice2x/games/otoca/p4io.cpp @@ -94,7 +94,7 @@ namespace games::otoca { bool kb_insert_press = false; // eamio keypress - kb_insert_press |= eamuse_get_keypad_state(0) & (1 << EAM_IO_INSERT); + kb_insert_press |= static_cast(eamuse_get_keypad_state(0) & (1 << EAM_IO_INSERT)); // check for card if (CARD_DATA == nullptr && (eamuse_card_insert_consume(1, 0) || kb_insert_press)) { diff --git a/src/spice2x/hooks/networkhook.cpp b/src/spice2x/hooks/networkhook.cpp index 9374b90..9925391 100644 --- a/src/spice2x/hooks/networkhook.cpp +++ b/src/spice2x/hooks/networkhook.cpp @@ -141,13 +141,17 @@ static ULONG WINAPI GetAdaptersInfo_hook(PIP_ADAPTER_INFO pAdapterInfo, PULONG p static int WINAPI bind_hook(SOCKET s, const struct sockaddr *name, int namelen) { +#ifdef __clang__ #pragma clang diagnostic push #pragma ide diagnostic ignored "OCDFAInspection" +#endif // cast to sockaddr_in struct sockaddr_in *in_name = (struct sockaddr_in *) name; +#ifdef __clang__ #pragma clang diagnostic pop +#endif // override bind to allow all hosts in_name->sin_addr.s_addr = inet_addr("0.0.0.0"); diff --git a/src/spice2x/launcher/options.cpp b/src/spice2x/launcher/options.cpp index a945a67..f83410e 100644 --- a/src/spice2x/launcher/options.cpp +++ b/src/spice2x/launcher/options.cpp @@ -2445,7 +2445,7 @@ std::unique_ptr> launcher::parse_options(int argc, char *arg } else { // validate it is an integer try { - std::stoull(argv[i], nullptr, 16); + auto _ = std::stoull(argv[i], nullptr, 16); } catch (const std::exception &ex) { log_fatal("options", "parameter for -{} is not a hex number: {}", alias, argv[i]); } diff --git a/src/spice2x/misc/extdev.cpp b/src/spice2x/misc/extdev.cpp index 343c5ea..7b3ad02 100644 --- a/src/spice2x/misc/extdev.cpp +++ b/src/spice2x/misc/extdev.cpp @@ -162,7 +162,7 @@ static void __cdecl cardunit_update() { bool kb_insert_press = false; // eamio keypress - kb_insert_press |= eamuse_get_keypad_state(unit) & (1 << EAM_IO_INSERT); + kb_insert_press |= static_cast(eamuse_get_keypad_state(unit) & (1 << EAM_IO_INSERT)); // update card inserts if (eamuse_card_insert_consume((int) EXTDEV_CARDUNIT_COUNT, unit) || diff --git a/src/spice2x/util/detour.cpp b/src/spice2x/util/detour.cpp index 40b1210..4a91820 100644 --- a/src/spice2x/util/detour.cpp +++ b/src/spice2x/util/detour.cpp @@ -106,8 +106,10 @@ bool detour::inline_restore(void *address, char *data) { #endif } +#ifdef __clang__ #pragma clang diagnostic push #pragma ide diagnostic ignored "OCDFAInspection" +#endif static void *pe_offset(void *ptr, size_t offset) { if (offset == 0) { @@ -282,7 +284,9 @@ void **detour::iat_find_proc(const char *iid_name, void *proc, HMODULE module) { return nullptr; } +#ifdef __clang__ #pragma clang diagnostic pop +#endif void *detour::iat_try(const char *function, void *new_func, HMODULE module, const char *iid_name) {