diff --git a/src/SFML/Network/Packet.cpp b/src/SFML/Network/Packet.cpp index 965685c7..3b638d43 100644 --- a/src/SFML/Network/Packet.cpp +++ b/src/SFML/Network/Packet.cpp @@ -123,7 +123,7 @@ Packet& Packet::operator >>(Int8& data) { if (checkSize(sizeof(data))) { - data = *reinterpret_cast(&m_data[m_readPos]); + std::memcpy(&data, &m_data[m_readPos], sizeof(data)); m_readPos += sizeof(data); } @@ -136,7 +136,7 @@ Packet& Packet::operator >>(Uint8& data) { if (checkSize(sizeof(data))) { - data = *reinterpret_cast(&m_data[m_readPos]); + std::memcpy(&data, &m_data[m_readPos], sizeof(data)); m_readPos += sizeof(data); } @@ -149,7 +149,8 @@ Packet& Packet::operator >>(Int16& data) { if (checkSize(sizeof(data))) { - data = ntohs(*reinterpret_cast(&m_data[m_readPos])); + std::memcpy(&data, &m_data[m_readPos], sizeof(data)); + data = ntohs(data); m_readPos += sizeof(data); } @@ -162,7 +163,8 @@ Packet& Packet::operator >>(Uint16& data) { if (checkSize(sizeof(data))) { - data = ntohs(*reinterpret_cast(&m_data[m_readPos])); + std::memcpy(&data, &m_data[m_readPos], sizeof(data)); + data = ntohs(data); m_readPos += sizeof(data); } @@ -175,7 +177,8 @@ Packet& Packet::operator >>(Int32& data) { if (checkSize(sizeof(data))) { - data = ntohl(*reinterpret_cast(&m_data[m_readPos])); + std::memcpy(&data, &m_data[m_readPos], sizeof(data)); + data = ntohl(data); m_readPos += sizeof(data); } @@ -188,7 +191,8 @@ Packet& Packet::operator >>(Uint32& data) { if (checkSize(sizeof(data))) { - data = ntohl(*reinterpret_cast(&m_data[m_readPos])); + std::memcpy(&data, &m_data[m_readPos], sizeof(data)); + data = ntohl(data); m_readPos += sizeof(data); } @@ -203,7 +207,8 @@ Packet& Packet::operator >>(Int64& data) { // Since ntohll is not available everywhere, we have to convert // to network byte order (big endian) manually - const Uint8* bytes = reinterpret_cast(&m_data[m_readPos]); + Uint8 bytes[sizeof(data)]; + std::memcpy(bytes, &m_data[m_readPos], sizeof(data)); data = (static_cast(bytes[0]) << 56) | (static_cast(bytes[1]) << 48) | (static_cast(bytes[2]) << 40) | @@ -226,7 +231,8 @@ Packet& Packet::operator >>(Uint64& data) { // Since ntohll is not available everywhere, we have to convert // to network byte order (big endian) manually - const Uint8* bytes = reinterpret_cast(&m_data[m_readPos]); + Uint8 bytes[sizeof(data)]; + std::memcpy(bytes, &m_data[m_readPos], sizeof(data)); data = (static_cast(bytes[0]) << 56) | (static_cast(bytes[1]) << 48) | (static_cast(bytes[2]) << 40) |