From 1d1415c982960db9ebc99c3793dc93ebef765f56 Mon Sep 17 00:00:00 2001 From: acsbendi Date: Tue, 16 Apr 2019 20:36:18 +0200 Subject: [PATCH] Avoid unaligned memory access when reading floats and doubles from Packet. --- src/SFML/Network/Packet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SFML/Network/Packet.cpp b/src/SFML/Network/Packet.cpp index 4fafb4cf..965685c7 100644 --- a/src/SFML/Network/Packet.cpp +++ b/src/SFML/Network/Packet.cpp @@ -247,7 +247,7 @@ Packet& Packet::operator >>(float& 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); } @@ -260,7 +260,7 @@ Packet& Packet::operator >>(double& 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); }