created FromBitsUnchecked memcpy wrapper

This commit is contained in:
jadebenn
2024-11-25 01:40:58 -06:00
parent 6fa719c679
commit 66fa3ff4ba
4 changed files with 28 additions and 8 deletions

View File

@@ -1396,9 +1396,8 @@ void HandlePacket(Packet* packet) {
}
default:
// Need to use memcpy instead of reinterpret_cast to avoid misaligned reads, which are UB
auto messageId = MessageType::World::INVALID;
std::memcpy(&messageId, &packet->data[3], sizeof(MessageType::World));
// Need to use FromBitsUnchecked (aka memcpy) instead of reinterpret_cast to avoid misaligned reads, which are UB
const auto messageId = GeneralUtils::FromBitsUnchecked<MessageType::World>(&packet->data[3]);
const std::string_view messageIdString = StringifiedEnum::ToString(messageId);
LOG("Unknown world packet received: %4i, %s", messageId, messageIdString.data());