From 17860edc4c3de72791acbc126c4fac9543b37cd4 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sun, 5 Jan 2025 20:34:54 +0100 Subject: [PATCH] Fix most conversion warnings --- src/common/network/address.cpp | 28 +++++++++---------- src/common/network/address.hpp | 11 ++++---- src/common/network/socket.cpp | 6 ++-- src/common/network/socket.hpp | 1 - src/windows-emulator/devices/afd_endpoint.cpp | 17 ++++------- src/windows-emulator/kusd_mmio.cpp | 4 +-- src/windows-emulator/memory_utils.hpp | 2 +- .../module/module_mapping.cpp | 2 +- src/windows-emulator/syscall_utils.hpp | 2 +- 9 files changed, 34 insertions(+), 39 deletions(-) diff --git a/src/common/network/address.cpp b/src/common/network/address.cpp index 837a6381..12e25508 100644 --- a/src/common/network/address.cpp +++ b/src/common/network/address.cpp @@ -57,7 +57,7 @@ namespace network this->address4_ = addr; } - address::address(const sockaddr* addr, const int length) + address::address(const sockaddr* addr, const socklen_t length) : address() { this->set_address(addr, length); @@ -109,7 +109,7 @@ namespace network this->address6_.sin6_addr = addr; } - void address::set_address(const sockaddr* addr, const int length) + void address::set_address(const sockaddr* addr, const socklen_t length) { if (static_cast(length) >= sizeof(sockaddr_in) && addr->sa_family == AF_INET) { @@ -250,29 +250,29 @@ namespace network return this->address6_; } - int address::get_size() const + socklen_t address::get_size() const { switch (this->address_.sa_family) { case AF_INET: - return static_cast(sizeof(this->address4_)); + return static_cast(sizeof(this->address4_)); case AF_INET6: - return static_cast(sizeof(this->address6_)); + return static_cast(sizeof(this->address6_)); default: - return static_cast(sizeof(this->address_)); + return static_cast(sizeof(this->address_)); } } - int address::get_max_size() const + socklen_t address::get_max_size() const { - const auto s = sizeof(this->address_); - const auto s4 = sizeof(this->address4_); - const auto s6 = sizeof(this->address6_); - const auto sstore = sizeof(this->storage_); - const auto max_size = std::max(sstore, std::max(s, std::max(s4, s6))); + constexpr auto s = sizeof(this->address_); + constexpr auto s4 = sizeof(this->address4_); + constexpr auto s6 = sizeof(this->address6_); + constexpr auto sstore = sizeof(this->storage_); + constexpr auto max_size = std::max(sstore, std::max(s, std::max(s4, s6))); static_assert(max_size == sstore); - return max_size; + return static_cast(max_size); } bool address::is_ipv4() const @@ -349,7 +349,7 @@ namespace network if (i->ai_family == AF_INET || i->ai_family == AF_INET6) { address a{}; - a.set_address(i->ai_addr, static_cast(i->ai_addrlen)); + a.set_address(i->ai_addr, static_cast(i->ai_addrlen)); results.emplace_back(std::move(a)); } } diff --git a/src/common/network/address.hpp b/src/common/network/address.hpp index ecf1e657..1351f198 100644 --- a/src/common/network/address.hpp +++ b/src/common/network/address.hpp @@ -21,7 +21,7 @@ #include -#define ZeroMemory(x, y) memset(x, 0, static_cast(y)) +#define ZeroMemory(x, y) memset(x, 0, y) #endif @@ -30,6 +30,7 @@ #include #ifdef _WIN32 +using socklen_t = int; #pragma comment(lib, "ws2_32.lib") #endif @@ -44,12 +45,12 @@ namespace network address(const std::string& addr, const std::optional& family = {}); address(const sockaddr_in& addr); address(const sockaddr_in6& addr); - address(const sockaddr* addr, int length); + address(const sockaddr* addr, socklen_t length); void set_ipv4(uint32_t ip); void set_ipv4(const in_addr& addr); void set_ipv6(const in6_addr& addr); - void set_address(const sockaddr* addr, int length); + void set_address(const sockaddr* addr, socklen_t length); void set_port(unsigned short port); [[nodiscard]] unsigned short get_port() const; @@ -62,8 +63,8 @@ namespace network const sockaddr_in& get_in_addr() const; const sockaddr_in6& get_in6_addr() const; - int get_size() const; - int get_max_size() const; + socklen_t get_size() const; + socklen_t get_max_size() const; bool is_ipv4() const; bool is_ipv6() const; diff --git a/src/common/network/socket.cpp b/src/common/network/socket.cpp index 1ff9d2af..c8d8fc2a 100644 --- a/src/common/network/socket.cpp +++ b/src/common/network/socket.cpp @@ -57,7 +57,7 @@ namespace network bool socket::bind_port(const address& target) { - const auto result = bind(this->socket_, &target.get_addr(), static_cast(target.get_size())) == 0; + const auto result = bind(this->socket_, &target.get_addr(), target.get_size()) == 0; if (result) { this->port_ = target.get_port(); @@ -70,7 +70,7 @@ namespace network { const auto res = sendto(this->socket_, static_cast(data), static_cast(size), 0, &target.get_addr(), - static_cast(target.get_size())); + target.get_size()); return static_cast(res) == size; } @@ -82,7 +82,7 @@ namespace network bool socket::receive(address& source, std::string& data) const { char buffer[0x2000]; - auto len = static_cast(source.get_max_size()); + auto len = source.get_max_size(); const auto result = recvfrom(this->socket_, buffer, static_cast(sizeof(buffer)), 0, &source.get_addr(), &len); diff --git a/src/common/network/socket.hpp b/src/common/network/socket.hpp index 17c48628..ef8f1d35 100644 --- a/src/common/network/socket.hpp +++ b/src/common/network/socket.hpp @@ -6,7 +6,6 @@ #include #ifdef _WIN32 -using socklen_t = int; using send_size = int; #define GET_SOCKET_ERROR() (WSAGetLastError()) #define poll WSAPoll diff --git a/src/windows-emulator/devices/afd_endpoint.cpp b/src/windows-emulator/devices/afd_endpoint.cpp index b3f902d5..8b9766ce 100644 --- a/src/windows-emulator/devices/afd_endpoint.cpp +++ b/src/windows-emulator/devices/afd_endpoint.cpp @@ -354,7 +354,7 @@ namespace } const auto* address = reinterpret_cast(data.data() + address_offset); - const auto address_size = static_cast(data.size() - address_offset); + const auto address_size = static_cast(data.size() - address_offset); const network::address addr(address, address_size); @@ -451,18 +451,13 @@ namespace return STATUS_INVALID_PARAMETER; } - int fromlength = static_cast(address.size()); + auto fromlength = static_cast(address.size()); std::vector data{}; data.resize(buffer.len); -#ifdef OS_WINDOWS - const auto recevied_data = recvfrom(*this->s_, data.data(), static_cast(data.size()), 0, + const auto recevied_data = recvfrom(*this->s_, data.data(), static_cast(data.size()), 0, reinterpret_cast(address.data()), &fromlength); -#else - const auto recevied_data = recvfrom(*this->s_, data.data(), static_cast(data.size()), 0, - reinterpret_cast(address.data()), (socklen_t*)&fromlength); -#endif if (recevied_data < 0) { @@ -508,15 +503,15 @@ namespace const auto buffer = emu.read_memory>>(send_info.BufferArray); const auto address = emu.read_memory(send_info.TdiConnInfo.RemoteAddress, - send_info.TdiConnInfo.RemoteAddressLength); + static_cast(send_info.TdiConnInfo.RemoteAddressLength)); const network::address target(reinterpret_cast(address.data()), - static_cast(address.size())); + static_cast(address.size())); const auto data = emu.read_memory(buffer.buf, buffer.len); const auto sent_data = sendto(*this->s_, reinterpret_cast(data.data()), - static_cast(data.size()), 0 /* ? */, &target.get_addr(), + static_cast(data.size()), 0 /* ? */, &target.get_addr(), target.get_size()); if (sent_data < 0) diff --git a/src/windows-emulator/kusd_mmio.cpp b/src/windows-emulator/kusd_mmio.cpp index 5b295a45..b88e2d23 100644 --- a/src/windows-emulator/kusd_mmio.cpp +++ b/src/windows-emulator/kusd_mmio.cpp @@ -183,7 +183,7 @@ void kusd_mmio::update() if (this->use_relative_time_) { const auto passed_time = this->process_->executed_instructions; - const auto clock_frequency = this->kusd_.QpcFrequency; + const auto clock_frequency = static_cast(this->kusd_.QpcFrequency); using duration = std::chrono::system_clock::duration; time += duration(passed_time * duration::period::den / clock_frequency); @@ -209,7 +209,7 @@ void kusd_mmio::register_mmio() [this](const uint64_t addr, const size_t size) { return this->read(addr, size); - }, [this](const uint64_t, const size_t, const uint64_t) + }, [](const uint64_t, const size_t, const uint64_t) { // Writing not supported! }); diff --git a/src/windows-emulator/memory_utils.hpp b/src/windows-emulator/memory_utils.hpp index 40fbcf58..30d36851 100644 --- a/src/windows-emulator/memory_utils.hpp +++ b/src/windows-emulator/memory_utils.hpp @@ -21,7 +21,7 @@ inline std::string get_permission_string(const memory_permission permission) inline memory_permission map_nt_to_emulator_protection(uint32_t nt_protection) { - nt_protection &= ~PAGE_GUARD; // TODO: Implement that + nt_protection &= ~static_cast(PAGE_GUARD); // TODO: Implement that switch (nt_protection) { diff --git a/src/windows-emulator/module/module_mapping.cpp b/src/windows-emulator/module/module_mapping.cpp index 1a1ebe54..4a3ff46a 100644 --- a/src/windows-emulator/module/module_mapping.cpp +++ b/src/windows-emulator/module/module_mapping.cpp @@ -118,7 +118,7 @@ namespace const auto entry = entries.get(i); const int type = entry >> 12; - const int offset = entry & 0xfff; + const auto offset = static_cast(entry & 0xfff); const auto total_offset = relocation.VirtualAddress + offset; switch (type) diff --git a/src/windows-emulator/syscall_utils.hpp b/src/windows-emulator/syscall_utils.hpp index 8cfe6bad..41819729 100644 --- a/src/windows-emulator/syscall_utils.hpp +++ b/src/windows-emulator/syscall_utils.hpp @@ -273,7 +273,7 @@ inline std::chrono::system_clock::time_point convert_from_ksystem_time(const vol } #ifndef OS_WINDOWS -using __time64_t = uint64_t; +using __time64_t = int64_t; #endif inline LARGE_INTEGER convert_unix_to_windows_time(const __time64_t unix_time)