mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-18 19:23:56 +00:00
Fix most conversion warnings
This commit is contained in:
@@ -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<size_t>(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<int>(sizeof(this->address4_));
|
||||
return static_cast<socklen_t>(sizeof(this->address4_));
|
||||
case AF_INET6:
|
||||
return static_cast<int>(sizeof(this->address6_));
|
||||
return static_cast<socklen_t>(sizeof(this->address6_));
|
||||
default:
|
||||
return static_cast<int>(sizeof(this->address_));
|
||||
return static_cast<socklen_t>(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<socklen_t>(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<int>(i->ai_addrlen));
|
||||
a.set_address(i->ai_addr, static_cast<socklen_t>(i->ai_addrlen));
|
||||
results.emplace_back(std::move(a));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#define ZeroMemory(x, y) memset(x, 0, static_cast<size_t>(y))
|
||||
#define ZeroMemory(x, y) memset(x, 0, y)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <optional>
|
||||
|
||||
#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<int>& 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;
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace network
|
||||
|
||||
bool socket::bind_port(const address& target)
|
||||
{
|
||||
const auto result = bind(this->socket_, &target.get_addr(), static_cast<socklen_t>(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<const char*>(data), static_cast<send_size>(size), 0,
|
||||
&target.get_addr(),
|
||||
static_cast<socklen_t>(target.get_size()));
|
||||
target.get_size());
|
||||
return static_cast<size_t>(res) == size;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace network
|
||||
bool socket::receive(address& source, std::string& data) const
|
||||
{
|
||||
char buffer[0x2000];
|
||||
auto len = static_cast<socklen_t>(source.get_max_size());
|
||||
auto len = source.get_max_size();
|
||||
|
||||
const auto result = recvfrom(this->socket_, buffer, static_cast<int>(sizeof(buffer)), 0, &source.get_addr(),
|
||||
&len);
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include <chrono>
|
||||
|
||||
#ifdef _WIN32
|
||||
using socklen_t = int;
|
||||
using send_size = int;
|
||||
#define GET_SOCKET_ERROR() (WSAGetLastError())
|
||||
#define poll WSAPoll
|
||||
|
||||
@@ -354,7 +354,7 @@ namespace
|
||||
}
|
||||
|
||||
const auto* address = reinterpret_cast<const sockaddr*>(data.data() + address_offset);
|
||||
const auto address_size = static_cast<int>(data.size() - address_offset);
|
||||
const auto address_size = static_cast<socklen_t>(data.size() - address_offset);
|
||||
|
||||
const network::address addr(address, address_size);
|
||||
|
||||
@@ -451,18 +451,13 @@ namespace
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
int fromlength = static_cast<int>(address.size());
|
||||
auto fromlength = static_cast<socklen_t>(address.size());
|
||||
|
||||
std::vector<char> data{};
|
||||
data.resize(buffer.len);
|
||||
|
||||
#ifdef OS_WINDOWS
|
||||
const auto recevied_data = recvfrom(*this->s_, data.data(), static_cast<int>(data.size()), 0,
|
||||
const auto recevied_data = recvfrom(*this->s_, data.data(), static_cast<send_size>(data.size()), 0,
|
||||
reinterpret_cast<sockaddr*>(address.data()), &fromlength);
|
||||
#else
|
||||
const auto recevied_data = recvfrom(*this->s_, data.data(), static_cast<int>(data.size()), 0,
|
||||
reinterpret_cast<sockaddr*>(address.data()), (socklen_t*)&fromlength);
|
||||
#endif
|
||||
|
||||
if (recevied_data < 0)
|
||||
{
|
||||
@@ -508,15 +503,15 @@ namespace
|
||||
const auto buffer = emu.read_memory<EMU_WSABUF<EmulatorTraits<Emu64>>>(send_info.BufferArray);
|
||||
|
||||
const auto address = emu.read_memory(send_info.TdiConnInfo.RemoteAddress,
|
||||
send_info.TdiConnInfo.RemoteAddressLength);
|
||||
static_cast<size_t>(send_info.TdiConnInfo.RemoteAddressLength));
|
||||
|
||||
const network::address target(reinterpret_cast<const sockaddr*>(address.data()),
|
||||
static_cast<int>(address.size()));
|
||||
static_cast<socklen_t>(address.size()));
|
||||
|
||||
const auto data = emu.read_memory(buffer.buf, buffer.len);
|
||||
|
||||
const auto sent_data = sendto(*this->s_, reinterpret_cast<const char*>(data.data()),
|
||||
static_cast<int>(data.size()), 0 /* ? */, &target.get_addr(),
|
||||
static_cast<send_size>(data.size()), 0 /* ? */, &target.get_addr(),
|
||||
target.get_size());
|
||||
|
||||
if (sent_data < 0)
|
||||
|
||||
@@ -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<uint64_t>(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!
|
||||
});
|
||||
|
||||
@@ -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<uint32_t>(PAGE_GUARD); // TODO: Implement that
|
||||
|
||||
switch (nt_protection)
|
||||
{
|
||||
|
||||
@@ -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<uint16_t>(entry & 0xfff);
|
||||
const auto total_offset = relocation.VirtualAddress + offset;
|
||||
|
||||
switch (type)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user