From a5552e612c3b7970eb9a47dd94b556a3c782029d Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Wed, 29 Jul 2026 18:34:51 +0200 Subject: Replace functional cast with `static_cast` --- Source/Core/Core/ARDecrypt.cpp | 10 +++++----- Source/Core/Core/FreeLookManager.cpp | 2 +- Source/Core/Core/LibusbUtils.cpp | 4 ++-- Source/Core/Core/Movie.cpp | 6 +++--- Source/Core/Core/NetPlayClient.cpp | 3 ++- Source/Core/Core/NetPlayServer.cpp | 13 +++++++------ Source/Core/Core/State.cpp | 24 ++++++++++++------------ Source/Core/Core/State.h | 8 ++++---- Source/Core/Core/WiiUtils.cpp | 2 +- 9 files changed, 37 insertions(+), 35 deletions(-) diff --git a/Source/Core/Core/ARDecrypt.cpp b/Source/Core/Core/ARDecrypt.cpp index b94b36de5a..64b66528f0 100644 --- a/Source/Core/Core/ARDecrypt.cpp +++ b/Source/Core/Core/ARDecrypt.cpp @@ -152,8 +152,8 @@ constexpr Seeds genseeds = [] { for (size_t i = 0; i < array0.size(); ++i) { - const auto tmp = u8(gentable0[i] - 1); - array0[i] = (u32(0 - (gensubtable[tmp >> 3] & gentable1[tmp & 7])) >> 31); + const auto tmp = static_cast(gentable0[i] - 1); + array0[i] = (static_cast(0 - (gensubtable[tmp >> 3] & gentable1[tmp & 7])) >> 31); } for (int i = 0; i < 0x10; ++i) @@ -165,7 +165,7 @@ constexpr Seeds genseeds = [] { for (u32 j = 0; j < 0x38; j++) { - auto tmp = u8(tmp2 + j); + auto tmp = static_cast(tmp2 + j); if (j > 0x1B) { @@ -347,7 +347,7 @@ static bool GetBitString(u32* ctrl, u32* out, u8 len) static std::optional BatchDecrypt(std::span codes) { - const auto size = u32(codes.size()); + const auto size = static_cast(codes.size()); assert((size & 1) == 0); assert(size != 0); @@ -383,7 +383,7 @@ static std::optional BatchDecrypt(std::span codes) static u32 GetVal(char chr) { - const auto ret = u32(strchr(filter, Common::ToUpper(chr)) - filter); + const auto ret = static_cast(strchr(filter, Common::ToUpper(chr)) - filter); switch (ret) { case 32: // 'I' diff --git a/Source/Core/Core/FreeLookManager.cpp b/Source/Core/Core/FreeLookManager.cpp index 9dc23e8934..146e71cc1d 100644 --- a/Source/Core/Core/FreeLookManager.cpp +++ b/Source/Core/Core/FreeLookManager.cpp @@ -114,7 +114,7 @@ FreeLookController::FreeLookController(const unsigned int index) : m_index(index std::string FreeLookController::GetName() const { - return std::string("FreeLook") + char('1' + m_index); + return std::string("FreeLook") + static_cast('1' + m_index); } InputConfig* FreeLookController::GetConfig() const diff --git a/Source/Core/Core/LibusbUtils.cpp b/Source/Core/Core/LibusbUtils.cpp index fdb2ecd209..1c034b44b4 100644 --- a/Source/Core/Core/LibusbUtils.cpp +++ b/Source/Core/Core/LibusbUtils.cpp @@ -168,7 +168,7 @@ std::optional GetStringDescriptor(libusb_device_handle* dev_handle, if (lang_id_result != 4 || buffer.length < 4 || buffer.descriptor_type != LIBUSB_DT_STRING) { ERROR_LOG_FMT(IOS_USB, "libusb_get_string_descriptor(desc_index={}, lang_id=0) result:{}", - int(desc_index), lang_id_result); + static_cast(desc_index), lang_id_result); return std::nullopt; } @@ -180,7 +180,7 @@ std::optional GetStringDescriptor(libusb_device_handle* dev_handle, if (str_result < 2 || buffer.length > str_result || buffer.descriptor_type != LIBUSB_DT_STRING) { ERROR_LOG_FMT(IOS_USB, "libusb_get_string_descriptor(desc_index={}, lang_id={}) result:{}", - int(desc_index), lang_id, str_result); + static_cast(desc_index), lang_id, str_result); return std::nullopt; } diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index c336becd07..047fbfc81a 100644 --- a/Source/Core/Core/Movie.cpp +++ b/Source/Core/Core/Movie.cpp @@ -1226,8 +1226,8 @@ bool MovieManager::PlayWiimote(int wiimote, DesiredWiimoteState* desired_state) if (serialized.length > serialized.data.size()) { - PanicAlertFmtT("Invalid serialized length:{0} in PlayWiimote. byte:{1}", int(serialized.length), - m_current_byte); + PanicAlertFmtT("Invalid serialized length:{0} in PlayWiimote. byte:{1}", + static_cast(serialized.length), m_current_byte); EndPlayInput(!m_read_only); return false; } @@ -1236,7 +1236,7 @@ bool MovieManager::PlayWiimote(int wiimote, DesiredWiimoteState* desired_state) if (m_current_byte + serialized.length > m_temp_input.size()) { PanicAlertFmtT("Premature movie end in PlayWiimote. {0} + {1} > {2}", m_current_byte, - int(serialized.length), m_temp_input.size()); + static_cast(serialized.length), m_temp_input.size()); EndPlayInput(!m_read_only); return false; } diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 2cd9ae2801..df54510e53 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -1648,7 +1648,8 @@ void NetPlayClient::ThreadFunc() if (static_cast(netEvent.type) == Common::ENet::SKIPPABLE_EVENT) INFO_LOG_FMT(NETPLAY, "enet_host_service: skippable packet event"); else - ERROR_LOG_FMT(NETPLAY, "enet_host_service: unknown event type: {}", int(netEvent.type)); + ERROR_LOG_FMT(NETPLAY, "enet_host_service: unknown event type: {}", + static_cast(netEvent.type)); break; } } diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index 834544b6b3..20e1096c28 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -326,7 +326,7 @@ void NetPlayServer::ThreadFunc() if (error != ConnectionError::NoError) { - INFO_LOG_FMT(NETPLAY, "Error {} initializing peer {:x}:{}", u8(error), + INFO_LOG_FMT(NETPLAY, "Error {} initializing peer {:x}:{}", static_cast(error), netEvent.peer->address.host, netEvent.peer->address.port); sf::Packet spac; @@ -391,7 +391,8 @@ void NetPlayServer::ThreadFunc() if (static_cast(netEvent.type) == Common::ENet::SKIPPABLE_EVENT) INFO_LOG_FMT(NETPLAY, "enet_host_service: skippable packet event"); else - ERROR_LOG_FMT(NETPLAY, "enet_host_service: unknown event type: {}", int(netEvent.type)); + ERROR_LOG_FMT(NETPLAY, "enet_host_service: unknown event type: {}", + static_cast(netEvent.type)); break; } } @@ -1157,8 +1158,8 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player) SyncSaveDataID sub_id; packet >> sub_id; - INFO_LOG_FMT(NETPLAY, "Got client SyncSaveData message: {:x} from client {}", u8(sub_id), - player.pid); + INFO_LOG_FMT(NETPLAY, "Got client SyncSaveData message: {:x} from client {}", + static_cast(sub_id), player.pid); switch (sub_id) { @@ -1214,8 +1215,8 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player) SyncCodeID sub_id; packet >> sub_id; - INFO_LOG_FMT(NETPLAY, "Got client SyncCodes message: {:x} from client {}", u8(sub_id), - player.pid); + INFO_LOG_FMT(NETPLAY, "Got client SyncCodes message: {:x} from client {}", + static_cast(sub_id), player.pid); // Check If Code Sync was successful or not switch (sub_id) diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp index 765e0d6906..2dcd2cae2b 100644 --- a/Source/Core/Core/State.cpp +++ b/Source/Core/Core/State.cpp @@ -263,15 +263,15 @@ namespace struct SlotWithTimestamp { // 1-based indexing. - int slot; + u32 slot; double timestamp; }; } // namespace // Returns first slot number (1-based indexing) not in the vector. -static std::optional GetEmptySlot(std::span used_slots) +static std::optional GetEmptySlot(std::span used_slots) { - for (int i = 1; i <= int(NUM_STATES); ++i) + for (u32 i = 1; i <= NUM_STATES; ++i) { if (!Common::Contains(used_slots, i, &SlotWithTimestamp::slot)) return i; @@ -303,7 +303,7 @@ static std::string SystemTimeAsDoubleToString(double time) return fmt::format(std::locale{""}, "{:%x %X}", *local_time); } -static std::string MakeStateFilename(int number) +static std::string MakeStateFilename(u32 number) { return fmt::format("{}{}.s{:02d}", File::GetUserPath(D_STATESAVES_IDX), SConfig::GetInstance().GetGameID(), number); @@ -313,7 +313,7 @@ static std::vector GetUsedSlotsWithTimestamp() { std::vector result; StateHeader header; - for (int i = 1; i <= int(NUM_STATES); ++i) + for (u32 i = 1; i <= NUM_STATES; ++i) { std::string filename = MakeStateFilename(i); if (!File::Exists(filename) || !ReadHeader(filename, header)) @@ -337,7 +337,7 @@ static void CompressBufferToFile(std::span raw_buffer, File::IOFile& f Common::UniqueBuffer compressed_buffer(LZ4_compressBound(bytes_to_compress)); const int compressed_len = LZ4_compress_default( reinterpret_cast(raw_buffer.data()) + total_bytes_compressed, - compressed_buffer.get(), bytes_to_compress, int(compressed_buffer.size())); + compressed_buffer.get(), bytes_to_compress, static_cast(compressed_buffer.size())); if (compressed_len == 0) { @@ -474,7 +474,7 @@ static void SaveAsFromCore(Core::System& system, std::string filename) { // Try with a buffer a bit larger than the previous state. // This will often avoid the "Measure" step. - const auto buffer_size_estimate = std::size_t(s_last_state_size) * 110 / 100; + const auto buffer_size_estimate = static_cast(s_last_state_size) * 110 / 100; Common::UniqueBuffer buffer{buffer_size_estimate}; if (const auto actual_size = SaveToBuffer(system, buffer)) @@ -608,7 +608,7 @@ static bool ReadHeader(const std::string& filename, StateHeader& header) return ReadStateHeaderFromFile(header, f, get_version_header); } -std::string GetInfoStringOfSlot(int slot, bool translate) +std::string GetInfoStringOfSlot(u32 slot, bool translate) { std::lock_guard lk{s_state_saves_in_progress}; @@ -623,7 +623,7 @@ std::string GetInfoStringOfSlot(int slot, bool translate) return SystemTimeAsDoubleToString(header.legacy_header.time); } -u64 GetUnixTimeOfSlot(int slot) +u64 GetUnixTimeOfSlot(u32 slot) { std::lock_guard lk{s_state_saves_in_progress}; @@ -902,12 +902,12 @@ void Shutdown() s_flush_unsaved_data_hook.reset(); } -void Save(Core::System& system, int slot) +void Save(Core::System& system, u32 slot) { SaveAs(system, MakeStateFilename(slot)); } -void Load(Core::System& system, int slot) +void Load(Core::System& system, u32 slot) { LoadAs(system, MakeStateFilename(slot)); } @@ -922,7 +922,7 @@ void LoadLastSaved(Core::System& system, int i) s_compress_and_dump_thread.WaitForCompletion(); std::vector used_slots = GetUsedSlotsWithTimestamp(); - if (std::size_t(i) > used_slots.size()) + if (static_cast(i) > used_slots.size()) { Core::DisplayMessage("State doesn't exist", 2000); return; diff --git a/Source/Core/Core/State.h b/Source/Core/Core/State.h index 1c4eeb0554..cd35ea1af0 100644 --- a/Source/Core/Core/State.h +++ b/Source/Core/Core/State.h @@ -84,16 +84,16 @@ void Shutdown(); // Returns a string containing information of the savestate in the given slot // which can be presented to the user for identification purposes -std::string GetInfoStringOfSlot(int slot, bool translate = true); +std::string GetInfoStringOfSlot(u32 slot, bool translate = true); // Returns when the savestate in the given slot was created, or 0 if the slot is empty. -u64 GetUnixTimeOfSlot(int slot); +u64 GetUnixTimeOfSlot(u32 slot); // These don't happen instantly - they get scheduled as events. // ...But only if we're not in the main CPU thread. // If we're in the main CPU thread then they run immediately instead. -void Save(Core::System& system, int slot); -void Load(Core::System& system, int slot); +void Save(Core::System& system, u32 slot); +void Load(Core::System& system, u32 slot); void SaveAs(Core::System& system, std::string filename); void LoadAs(Core::System& system, std::string filename); diff --git a/Source/Core/Core/WiiUtils.cpp b/Source/Core/Core/WiiUtils.cpp index c22e9c8048..8c462fecf3 100644 --- a/Source/Core/Core/WiiUtils.cpp +++ b/Source/Core/Core/WiiUtils.cpp @@ -329,7 +329,7 @@ std::string SystemUpdater::GetDeviceId() u32 ios_device_id; if (m_ios.GetESCore().GetDeviceId(&ios_device_id) < 0) return ""; - return std::to_string((u64(1) << 32) | ios_device_id); + return std::to_string((1ULL << 32) | ios_device_id); } class OnlineSystemUpdater final : public SystemUpdater -- cgit v1.2.3