fix: strict aliasing violation in handleQueryNextMailTime

reinterpret_cast<float*> on raw packet bytes is undefined behavior per
the C++ strict aliasing rule — compilers can optimize assuming uint8_t
and float never alias. Replaced with packet.readFloat() which uses
memcpy internally. Also switched to hasRemaining() for consistency.
This commit is contained in:
Kelsi 2026-03-29 18:46:34 -07:00
parent 2ae14d5d38
commit fc2c6bab40

View file

@ -1665,9 +1665,10 @@ void InventoryHandler::handleReceivedMail(network::Packet& packet) {
}
void InventoryHandler::handleQueryNextMailTime(network::Packet& packet) {
if (packet.getSize() - packet.getReadPos() < 8) return;
float nextTime = *reinterpret_cast<const float*>(&packet.getData()[packet.getReadPos()]);
packet.readUInt32(); // skip
if (!packet.hasRemaining(8)) return;
// readFloat() uses memcpy internally, avoiding the strict aliasing violation
// that the previous reinterpret_cast<float*> on raw packet bytes had.
float nextTime = packet.readFloat();
uint32_t count = packet.readUInt32();
hasNewMail_ = (nextTime >= 0.0f && count > 0);
packet.setReadPos(packet.getSize());