diff --git a/third_party/sfml/src/SFML/Network/IpAddress.cpp b/third_party/sfml/src/SFML/Network/IpAddress.cpp index 02ae3a1d..b47b687b 100644 --- a/third_party/sfml/src/SFML/Network/IpAddress.cpp +++ b/third_party/sfml/src/SFML/Network/IpAddress.cpp @@ -65,9 +65,10 @@ nonstd::optional IpAddress::resolve(std::string address) return Any; // Try to convert the address as a byte representation ("xxx.xxx.xxx.xxx") - const std::uint32_t ip = inet_addr(address.data()); - if (ip != INADDR_NONE) - return IpAddress(ntohl(ip)); + std::uint32_t ipaddr = 0; + inet_pton(AF_INET, address.data(), &ipaddr); + if (ipaddr != INADDR_NONE) + return IpAddress(ntohl(ipaddr)); // Not a valid address, try to convert it as a host name addrinfo hints{}; // Zero-initialize @@ -106,10 +107,11 @@ IpAddress::IpAddress(std::uint32_t address) : m_address(address) //////////////////////////////////////////////////////////// std::string IpAddress::toString() const { + char address_str[INET_ADDRSTRLEN]; in_addr address{}; address.s_addr = htonl(m_address); - - return inet_ntoa(address); + inet_ntop(AF_INET, &address, address_str, INET_ADDRSTRLEN); + return address_str; } diff --git a/third_party/sfml/src/SFML/Network/TcpSocket.cpp b/third_party/sfml/src/SFML/Network/TcpSocket.cpp index fdb65fd3..78e883c4 100644 --- a/third_party/sfml/src/SFML/Network/TcpSocket.cpp +++ b/third_party/sfml/src/SFML/Network/TcpSocket.cpp @@ -42,7 +42,6 @@ #pragma warning(disable : 4127) // "conditional expression is constant" generated by the FD_SET macro #endif - namespace { // Low-level send/receive flags (OS-dependent) @@ -246,14 +245,11 @@ Socket::Status TcpSocket::send(const void* data, std::size_t size, std::size_t& int result = 0; for (sent = 0; sent < size; sent += static_cast(result)) { -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wuseless-cast" // Send a chunk of data result = static_cast(::send(getNativeHandle(), static_cast(data) + sent, static_cast(size - sent), flags)); -#pragma GCC diagnostic pop // Check for errors if (result < 0) @@ -283,14 +279,9 @@ Socket::Status TcpSocket::receive(void* data, std::size_t size, std::size_t& rec err() << "Cannot receive data from the network (the destination buffer is invalid)" << std::endl; return Status::Error; } - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wuseless-cast" // Receive a chunk of bytes const int sizeReceived = static_cast( recv(getNativeHandle(), static_cast(data), static_cast(size), flags)); -#pragma GCC diagnostic pop - // Check the number of bytes received if (sizeReceived > 0) { @@ -329,28 +320,15 @@ Socket::Status TcpSocket::send(Packet& packet) m_blockToSendBuffer.resize(sizeof(packetSize) + size); // Copy the packet size and data into the block to send -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wnull-dereference" // False positive. std::memcpy(m_blockToSendBuffer.data(), &packetSize, sizeof(packetSize)); -#pragma GCC diagnostic pop if (size > 0) std::memcpy(m_blockToSendBuffer.data() + sizeof(packetSize), data, size); -// These warnings are ignored here for portability, as even on Windows the -// signature of `send` might change depending on whether Win32 or MinGW is -// being used. -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wuseless-cast" -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wsign-conversion" // Send the data block std::size_t sent = 0; const Status status = send(m_blockToSendBuffer.data() + packet.m_sendPos, static_cast(m_blockToSendBuffer.size() - packet.m_sendPos), sent); -#pragma GCC diagnostic pop -#pragma GCC diagnostic pop - // In the case of a partial send, record the location to resume from if (status == Status::Partial) { diff --git a/third_party/sfml/src/SFML/Network/UdpSocket.cpp b/third_party/sfml/src/SFML/Network/UdpSocket.cpp index 05c10e8a..06700706 100644 --- a/third_party/sfml/src/SFML/Network/UdpSocket.cpp +++ b/third_party/sfml/src/SFML/Network/UdpSocket.cpp @@ -114,9 +114,6 @@ Socket::Status UdpSocket::send(const void* data, std::size_t size, IpAddress rem // Build the target address sockaddr_in address = SocketImpl::createAddress(remoteAddress.toInteger(), remotePort); - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wuseless-cast" // Send the data (unlike TCP, all the data is always sent in one call) const int sent = static_cast( sendto(getNativeHandle(), @@ -125,7 +122,6 @@ Socket::Status UdpSocket::send(const void* data, std::size_t size, IpAddress rem 0, reinterpret_cast(&address), sizeof(address))); -#pragma GCC diagnostic pop // Check for errors if (sent < 0) @@ -157,8 +153,6 @@ Socket::Status UdpSocket::receive(void* data, // Data that will be filled with the other computer's address sockaddr_in address = SocketImpl::createAddress(INADDR_ANY, 0); -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wuseless-cast" // Receive a chunk of bytes SocketImpl::AddrLength addressSize = sizeof(address); const int sizeReceived = static_cast( @@ -168,7 +162,6 @@ Socket::Status UdpSocket::receive(void* data, 0, reinterpret_cast(&address), &addressSize)); -#pragma GCC diagnostic pop // Check for errors if (sizeReceived < 0) diff --git a/third_party/sfml/src/SFML/System/Utils.hpp b/third_party/sfml/src/SFML/System/Utils.hpp index 59de12c8..ee2f1ceb 100644 --- a/third_party/sfml/src/SFML/System/Utils.hpp +++ b/third_party/sfml/src/SFML/System/Utils.hpp @@ -47,14 +47,14 @@ namespace sf template [[nodiscard]] constexpr IntegerType toInteger(std::array bytes) { - return ((IntegerType)(bytes[0] << 0)+ - (IntegerType)(bytes[1] << 8)+ - (IntegerType)(bytes[2] << 16)+ - (IntegerType)(bytes[3] << 24)+ - (IntegerType)(bytes[4] << 32)+ - (IntegerType)(bytes[5] << 40)+ - (IntegerType)(bytes[6] << 48)+ - (IntegerType)(bytes[7] << 56)); + return (((IntegerType)bytes[0] << 0)+ + ((IntegerType)bytes[1] << 8)+ + ((IntegerType)bytes[2] << 16)+ + ((IntegerType)bytes[3] << 24)+ + ((IntegerType)bytes[4] << 32)+ + ((IntegerType)bytes[5] << 40)+ + ((IntegerType)bytes[6] << 48)+ + ((IntegerType)bytes[7] << 56)); } [[nodiscard]] SFML_SYSTEM_API std::FILE* openFile(const ghc::filesystem::path& filename, std::string mode);