Skip to content

Commit

Permalink
Fix misaligned address when cast 4lw code str to Int32
Browse files Browse the repository at this point in the history
  • Loading branch information
lzydmxy committed Sep 25, 2024
1 parent ddf4379 commit 12210aa
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Service/FourLetterCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ String IFourLetterCommand::toName(int32_t code)

int32_t IFourLetterCommand::toCode(const String & name)
{
int32_t res = *reinterpret_cast<const int32_t *>(name.data());
int32_t res;
std::memcpy(&res, name.data(), sizeof(res));
/// keep consistent with Coordination::read method by changing big endian to little endian.
return __builtin_bswap32(res);
return std::byteswap(res);
}

IFourLetterCommand::~IFourLetterCommand() = default;
Expand Down

0 comments on commit 12210aa

Please sign in to comment.