mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-27 05:23:51 +00:00
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:
parent
2ae14d5d38
commit
fc2c6bab40
1 changed files with 4 additions and 3 deletions
|
|
@ -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());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue