From fc2c6bab4096ad3789fddd5e3dc587b10a2544ad Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sun, 29 Mar 2026 18:46:34 -0700 Subject: [PATCH] fix: strict aliasing violation in handleQueryNextMailTime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit reinterpret_cast 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. --- src/game/inventory_handler.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/game/inventory_handler.cpp b/src/game/inventory_handler.cpp index 67c4e60d..cd7c2ae5 100644 --- a/src/game/inventory_handler.cpp +++ b/src/game/inventory_handler.cpp @@ -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(&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 on raw packet bytes had. + float nextTime = packet.readFloat(); uint32_t count = packet.readUInt32(); hasNewMail_ = (nextTime >= 0.0f && count > 0); packet.setReadPos(packet.getSize());