Avoid unaligned memory access when reading floats and doubles from Packet.

This commit is contained in:
acsbendi 2019-04-16 20:36:18 +02:00 committed by Lukas Dürrenberger
parent 5381308268
commit 1d1415c982

View File

@ -247,7 +247,7 @@ Packet& Packet::operator >>(float& data)
{ {
if (checkSize(sizeof(data))) if (checkSize(sizeof(data)))
{ {
data = *reinterpret_cast<const float*>(&m_data[m_readPos]); std::memcpy(&data, &m_data[m_readPos], sizeof(data));
m_readPos += sizeof(data); m_readPos += sizeof(data);
} }
@ -260,7 +260,7 @@ Packet& Packet::operator >>(double& data)
{ {
if (checkSize(sizeof(data))) if (checkSize(sizeof(data)))
{ {
data = *reinterpret_cast<const double*>(&m_data[m_readPos]); std::memcpy(&data, &m_data[m_readPos], sizeof(data));
m_readPos += sizeof(data); m_readPos += sizeof(data);
} }