Skip to content

Commit

Permalink
default-initialize message-id buffer to an invalid (but defined) stat…
Browse files Browse the repository at this point in the history
…e and trust the compiler to optimize it out
  • Loading branch information
jadebenn committed Nov 22, 2024
1 parent 5aa8b13 commit 051a0ba
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dCommon/dEnums/MessageType/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

namespace MessageType {
enum class World : uint32_t {
VALIDATION = 1, // Session info
INVALID = 0,
VALIDATION, // Session info
CHARACTER_LIST_REQUEST,
CHARACTER_CREATE_REQUEST,
LOGIN_REQUEST, // Character selected
Expand Down
2 changes: 1 addition & 1 deletion dWorldServer/WorldServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,7 @@ void HandlePacket(Packet* packet) {

default:
// Need to use memcpy instead of reinterpret_cast to avoid UB
MessageType::World messageId;
auto messageId = MessageType::World::INVALID;
std::memcpy(&messageId, &packet->data[3], sizeof(MessageType::World));

const std::string_view messageIdString = StringifiedEnum::ToString(messageId);
Expand Down

0 comments on commit 051a0ba

Please sign in to comment.