mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-18 19:23:56 +00:00
Fix clang-tidy warnings
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "address.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "../utils/finally.hpp"
|
||||
@@ -125,7 +126,7 @@ namespace network
|
||||
}
|
||||
}
|
||||
|
||||
void address::set_port(const unsigned short port)
|
||||
void address::set_port(const uint16_t port)
|
||||
{
|
||||
switch (this->get_family())
|
||||
{
|
||||
@@ -140,7 +141,7 @@ namespace network
|
||||
}
|
||||
}
|
||||
|
||||
unsigned short address::get_port() const
|
||||
uint16_t address::get_port() const
|
||||
{
|
||||
switch (this->get_family())
|
||||
{
|
||||
@@ -155,27 +156,27 @@ namespace network
|
||||
|
||||
std::string address::to_string() const
|
||||
{
|
||||
char buffer[1000] = {};
|
||||
std::string addr;
|
||||
std::string addr{};
|
||||
std::array<char, 1000> buffer{};
|
||||
|
||||
switch (this->get_family())
|
||||
{
|
||||
case AF_INET:
|
||||
inet_ntop(this->get_family(), &this->address4_.sin_addr, buffer, sizeof(buffer));
|
||||
addr = std::string(buffer);
|
||||
inet_ntop(this->get_family(), &this->address4_.sin_addr, buffer.data(), buffer.size());
|
||||
addr = std::string(buffer.data());
|
||||
break;
|
||||
case AF_INET6:
|
||||
inet_ntop(this->get_family(), &this->address6_.sin6_addr, buffer, sizeof(buffer));
|
||||
addr = "[" + std::string(buffer) + "]";
|
||||
inet_ntop(this->get_family(), &this->address6_.sin6_addr, buffer.data(), buffer.size());
|
||||
addr = "[" + std::string(buffer.data()) + "]";
|
||||
break;
|
||||
default:
|
||||
buffer[0] = '?';
|
||||
buffer[1] = 0;
|
||||
addr = std::string(buffer);
|
||||
addr = std::string(buffer.data());
|
||||
break;
|
||||
}
|
||||
|
||||
return addr + ":"s + std::to_string(this->get_port());
|
||||
return addr + ":" + std::to_string(this->get_port());
|
||||
}
|
||||
|
||||
bool address::is_local() const
|
||||
@@ -187,8 +188,8 @@ namespace network
|
||||
|
||||
// According to: https://en.wikipedia.org/wiki/Private_network
|
||||
|
||||
uint8_t bytes[4];
|
||||
memcpy(bytes, &this->address4_.sin_addr.s_addr, sizeof(bytes));
|
||||
std::array<uint8_t, 4> bytes{};
|
||||
memcpy(bytes.data(), &this->address4_.sin_addr.s_addr, bytes.size());
|
||||
|
||||
// 10.X.X.X
|
||||
if (bytes[0] == 10)
|
||||
@@ -346,7 +347,7 @@ namespace network
|
||||
{
|
||||
address a{};
|
||||
a.set_address(i->ai_addr, static_cast<socklen_t>(i->ai_addrlen));
|
||||
results.emplace_back(std::move(a));
|
||||
results.emplace_back(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -372,6 +373,8 @@ std::size_t std::hash<network::address>::operator()(const network::address& a) c
|
||||
std::string_view{reinterpret_cast<const char*>(a.get_in6_addr().sin6_addr.s6_addr),
|
||||
sizeof(a.get_in6_addr().sin6_addr.s6_addr)});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return hash;
|
||||
|
||||
@@ -63,8 +63,8 @@ namespace network
|
||||
void set_ipv6(const in6_addr& addr);
|
||||
void set_address(const sockaddr* addr, socklen_t length);
|
||||
|
||||
void set_port(unsigned short port);
|
||||
[[nodiscard]] unsigned short get_port() const;
|
||||
void set_port(uint16_t port);
|
||||
[[nodiscard]] uint16_t get_port() const;
|
||||
|
||||
sockaddr& get_addr();
|
||||
sockaddr_in& get_in_addr();
|
||||
|
||||
@@ -71,11 +71,13 @@ namespace network
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(readability-make-member-function-const)
|
||||
bool socket::bind(const address& target)
|
||||
{
|
||||
return ::bind(this->socket_, &target.get_addr(), target.get_size()) == 0;
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(readability-make-member-function-const)
|
||||
bool socket::set_blocking(const bool blocking)
|
||||
{
|
||||
return socket::set_blocking(this->socket_, blocking);
|
||||
@@ -89,7 +91,10 @@ namespace network
|
||||
#else
|
||||
int flags = fcntl(s, F_GETFL, 0);
|
||||
if (flags == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
flags = blocking ? (flags & ~O_NONBLOCK) : (flags | O_NONBLOCK);
|
||||
return fcntl(s, F_SETFL, flags) == 0;
|
||||
#endif
|
||||
@@ -97,30 +102,6 @@ namespace network
|
||||
|
||||
bool socket::sleep(const std::chrono::milliseconds timeout, const bool in_poll) const
|
||||
{
|
||||
/*fd_set fdr;
|
||||
FD_ZERO(&fdr);
|
||||
FD_SET(this->socket_, &fdr);
|
||||
|
||||
const auto msec = timeout.count();
|
||||
|
||||
timeval tv{};
|
||||
tv.tv_sec = static_cast<long>(msec / 1000ll);
|
||||
tv.tv_usec = static_cast<long>((msec % 1000) * 1000);
|
||||
|
||||
const auto retval = select(static_cast<int>(this->socket_) + 1, &fdr, nullptr, nullptr, &tv);
|
||||
if (retval == SOCKET_ERROR)
|
||||
{
|
||||
std::this_thread::sleep_for(1ms);
|
||||
return socket_is_ready;
|
||||
}
|
||||
|
||||
if (retval > 0)
|
||||
{
|
||||
return socket_is_ready;
|
||||
}
|
||||
|
||||
return !socket_is_ready;*/
|
||||
|
||||
std::vector<const socket*> sockets{};
|
||||
sockets.push_back(this);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "tcp_client_socket.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
|
||||
namespace network
|
||||
@@ -58,13 +59,13 @@ namespace network
|
||||
|
||||
std::optional<std::string> tcp_client_socket::receive(const std::optional<size_t> max_size)
|
||||
{
|
||||
char buffer[0x2000];
|
||||
const auto size = std::min(sizeof(buffer), max_size.value_or(sizeof(buffer)));
|
||||
std::array<char, 0x2000> buffer{};
|
||||
const auto size = std::min(buffer.size(), max_size.value_or(buffer.size()));
|
||||
|
||||
const auto result = recv(this->get_socket(), buffer, static_cast<int>(size), 0);
|
||||
const auto result = recv(this->get_socket(), buffer.data(), static_cast<int>(size), 0);
|
||||
if (result > 0)
|
||||
{
|
||||
return std::string(buffer, result);
|
||||
return std::string(buffer.data(), static_cast<size_t>(result));
|
||||
}
|
||||
|
||||
if (result == 0 || (result < 0 && GET_SOCKET_ERROR() == SERR(ECONNRESET)))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "udp_socket.hpp"
|
||||
#include <array>
|
||||
|
||||
namespace network
|
||||
{
|
||||
@@ -31,17 +32,17 @@ namespace network
|
||||
|
||||
std::optional<std::pair<address, std::string>> udp_socket::receive() const
|
||||
{
|
||||
char buffer[0x2000];
|
||||
std::array<char, 0x2000> buffer{};
|
||||
address source{};
|
||||
auto len = source.get_max_size();
|
||||
|
||||
const auto result =
|
||||
recvfrom(this->get_socket(), buffer, static_cast<int>(sizeof(buffer)), 0, &source.get_addr(), &len);
|
||||
recvfrom(this->get_socket(), buffer.data(), static_cast<int>(buffer.size()), 0, &source.get_addr(), &len);
|
||||
if (result == SOCKET_ERROR)
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return {{source, std::string(buffer, result)}};
|
||||
return {{source, std::string(buffer.data(), static_cast<size_t>(result))}};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "compression.hpp"
|
||||
|
||||
#include <zlib.h>
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
|
||||
namespace utils::compression
|
||||
@@ -58,20 +59,20 @@ namespace utils::compression
|
||||
|
||||
int ret{};
|
||||
size_t offset = 0;
|
||||
static thread_local uint8_t dest[ZCHUNK_SIZE] = {0};
|
||||
static thread_local std::array<uint8_t, ZCHUNK_SIZE> dest{};
|
||||
auto& stream = stream_container.get();
|
||||
|
||||
do
|
||||
{
|
||||
const auto input_size = std::min(sizeof(dest), data.size() - offset);
|
||||
const auto input_size = std::min(dest.size(), data.size() - offset);
|
||||
stream.avail_in = static_cast<uInt>(input_size);
|
||||
stream.next_in = reinterpret_cast<const Bytef*>(data.data()) + offset;
|
||||
offset += stream.avail_in;
|
||||
|
||||
do
|
||||
{
|
||||
stream.avail_out = sizeof(dest);
|
||||
stream.next_out = dest;
|
||||
stream.avail_out = static_cast<uInt>(dest.size());
|
||||
stream.next_out = dest.data();
|
||||
|
||||
ret = inflate(&stream, Z_NO_FLUSH);
|
||||
if (ret != Z_OK && ret != Z_STREAM_END)
|
||||
@@ -79,7 +80,7 @@ namespace utils::compression
|
||||
return {};
|
||||
}
|
||||
|
||||
buffer.insert(buffer.end(), dest, dest + sizeof(dest) - stream.avail_out);
|
||||
buffer.insert(buffer.end(), dest.data(), dest.data() + dest.size() - stream.avail_out);
|
||||
} while (stream.avail_out == 0);
|
||||
} while (ret != Z_STREAM_END);
|
||||
|
||||
@@ -102,4 +103,4 @@ namespace utils::compression
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,12 +51,17 @@ namespace utils::io
|
||||
bool read_file(const std::filesystem::path& file, std::vector<uint8_t>* data)
|
||||
{
|
||||
if (!data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
data->clear();
|
||||
|
||||
std::ifstream stream(file, std::ios::binary);
|
||||
if (!stream)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
*data = std::vector<uint8_t>{(std::istreambuf_iterator<char>(stream)), std::istreambuf_iterator<char>()};
|
||||
return true;
|
||||
@@ -108,14 +113,14 @@ namespace utils::io
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
for (auto& file : std::filesystem::recursive_directory_iterator(directory, code))
|
||||
for (const auto& file : std::filesystem::recursive_directory_iterator(directory, code))
|
||||
{
|
||||
files.push_back(file.path());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto& file : std::filesystem::directory_iterator(directory, code))
|
||||
for (const auto& file : std::filesystem::directory_iterator(directory, code))
|
||||
{
|
||||
files.push_back(file.path());
|
||||
}
|
||||
|
||||
@@ -64,7 +64,9 @@ namespace gdb_stub
|
||||
|
||||
void send_xfer_data(connection_handler& connection, const std::string& args, const std::string_view data)
|
||||
{
|
||||
size_t offset{}, length{};
|
||||
size_t offset{};
|
||||
size_t length{};
|
||||
|
||||
rt_assert(sscanf_s(args.c_str(), "%zx,%zx", &offset, &length) == 2);
|
||||
|
||||
if (offset >= data.size())
|
||||
|
||||
Reference in New Issue
Block a user