Skip to content

Commit

Permalink
Fix conversion warnings for the Network module
Browse files Browse the repository at this point in the history
  • Loading branch information
eXpl0it3r committed Apr 22, 2021
1 parent a62112b commit d88acdd
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/SFML/Network/Ftp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ Ftp::Response Ftp::DataChannel::open(Ftp::TransferMode mode)
// Extract the current number
while (isdigit(str[index]))
{
data[i] = data[i] * 10 + (str[index] - '0');
data[i] = data[i] * 10 + static_cast<Uint8>(str[index] - '0');
index++;
}

Expand Down
4 changes: 2 additions & 2 deletions src/SFML/Network/Http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ void Http::Response::parse(const std::string& data)
(toLower(version.substr(0, 5)) == "http/") &&
isdigit(version[5]) && isdigit(version[7]))
{
m_majorVersion = version[5] - '0';
m_minorVersion = version[7] - '0';
m_majorVersion = static_cast<unsigned int>(version[5] - '0');
m_minorVersion = static_cast<unsigned int>(version[7] - '0');
}
else
{
Expand Down
8 changes: 4 additions & 4 deletions src/SFML/Network/Packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Packet& Packet::operator >>(Int16& data)
if (checkSize(sizeof(data)))
{
std::memcpy(&data, &m_data[m_readPos], sizeof(data));
data = ntohs(data);
data = static_cast<Int16>(ntohs(data));
m_readPos += sizeof(data);
}

Expand Down Expand Up @@ -178,7 +178,7 @@ Packet& Packet::operator >>(Int32& data)
if (checkSize(sizeof(data)))
{
std::memcpy(&data, &m_data[m_readPos], sizeof(data));
data = ntohl(data);
data = static_cast<Int16>(ntohl(data));
m_readPos += sizeof(data);
}

Expand Down Expand Up @@ -412,7 +412,7 @@ Packet& Packet::operator <<(Uint8 data)
////////////////////////////////////////////////////////////
Packet& Packet::operator <<(Int16 data)
{
Int16 toWrite = htons(data);
Int16 toWrite = static_cast<Int16>(htons(data));
append(&toWrite, sizeof(toWrite));
return *this;
}
Expand All @@ -430,7 +430,7 @@ Packet& Packet::operator <<(Uint16 data)
////////////////////////////////////////////////////////////
Packet& Packet::operator <<(Int32 data)
{
Int32 toWrite = htonl(data);
Int32 toWrite = static_cast<Int16>(htonl(data));
append(&toWrite, sizeof(toWrite));
return *this;
}
Expand Down
12 changes: 6 additions & 6 deletions src/SFML/Network/TcpSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ Socket::Status TcpSocket::send(const void* data, std::size_t size, std::size_t&
}

// Loop until every byte has been sent
int result = 0;
for (sent = 0; sent < size; sent += result)
ssize_t result = 0;
for (sent = 0; sent < size; sent += static_cast<std::size_t>(result))
{
// Send a chunk of data
result = ::send(getHandle(), static_cast<const char*>(data) + sent, static_cast<int>(size - sent), flags);
result = ::send(getHandle(), static_cast<const char*>(data) + sent, static_cast<priv::SocketImpl::Size>(size - sent), flags);

// Check for errors
if (result < 0)
Expand Down Expand Up @@ -278,12 +278,12 @@ Socket::Status TcpSocket::receive(void* data, std::size_t size, std::size_t& rec
}

// Receive a chunk of bytes
int sizeReceived = recv(getHandle(), static_cast<char*>(data), static_cast<int>(size), flags);
std::size_t sizeReceived = static_cast<std::size_t>(recv(getHandle(), static_cast<char*>(data), static_cast<priv::SocketImpl::Size>(size), flags));

// Check the number of bytes received
if (sizeReceived > 0)
{
received = static_cast<std::size_t>(sizeReceived);
received = sizeReceived;
return Done;
}
else if (sizeReceived == 0)
Expand Down Expand Up @@ -326,7 +326,7 @@ Socket::Status TcpSocket::send(Packet& packet)

// Send the data block
std::size_t sent;
Status status = send(&blockToSend[0] + packet.m_sendPos, blockToSend.size() - packet.m_sendPos, sent);
Status status = send(&blockToSend[0] + packet.m_sendPos, static_cast<priv::SocketImpl::Size>(blockToSend.size() - packet.m_sendPos), sent);

// In the case of a partial send, record the location to resume from
if (status == Partial)
Expand Down
6 changes: 3 additions & 3 deletions src/SFML/Network/UdpSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Socket::Status UdpSocket::send(const void* data, std::size_t size, const IpAddre
sockaddr_in address = priv::SocketImpl::createAddress(remoteAddress.toInteger(), remotePort);

// Send the data (unlike TCP, all the data is always sent in one call)
int sent = sendto(getHandle(), static_cast<const char*>(data), static_cast<int>(size), 0, reinterpret_cast<sockaddr*>(&address), sizeof(address));
std::size_t sent = static_cast<std::size_t>(sendto(getHandle(), static_cast<const char*>(data), static_cast<priv::SocketImpl::Size>(size), 0, reinterpret_cast<sockaddr*>(&address), sizeof(address)));

// Check for errors
if (sent < 0)
Expand Down Expand Up @@ -144,14 +144,14 @@ Socket::Status UdpSocket::receive(void* data, std::size_t size, std::size_t& rec

// Receive a chunk of bytes
priv::SocketImpl::AddrLength addressSize = sizeof(address);
int sizeReceived = recvfrom(getHandle(), static_cast<char*>(data), static_cast<int>(size), 0, reinterpret_cast<sockaddr*>(&address), &addressSize);
std::size_t sizeReceived = static_cast<std::size_t>(recvfrom(getHandle(), static_cast<char*>(data), static_cast<priv::SocketImpl::Size>(size), 0, reinterpret_cast<sockaddr*>(&address), &addressSize));

// Check for errors
if (sizeReceived < 0)
return priv::SocketImpl::getErrorStatus();

// Fill the sender informations
received = static_cast<std::size_t>(sizeReceived);
received = sizeReceived;
remoteAddress = IpAddress(ntohl(address.sin_addr.s_addr));
remotePort = ntohs(address.sin_port);

Expand Down
1 change: 1 addition & 0 deletions src/SFML/Network/Unix/SocketImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SocketImpl
// Types
////////////////////////////////////////////////////////////
typedef socklen_t AddrLength;
typedef size_t Size;

////////////////////////////////////////////////////////////
/// \brief Create an internal sockaddr_in address
Expand Down
1 change: 1 addition & 0 deletions src/SFML/Network/Win32/SocketImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class SocketImpl
// Types
////////////////////////////////////////////////////////////
typedef int AddrLength;
typedef int Size;

////////////////////////////////////////////////////////////
/// \brief Create an internal sockaddr_in address
Expand Down

0 comments on commit d88acdd

Please sign in to comment.