diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2021-01-11 17:39:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-11 17:39:43 +0100 |
commit | eeb63b8901a9c049f1bb594abb9ce9b4a9c47620 (patch) | |
tree | b07daae788f918b83eeb0bdbd51e49292f1c8d88 /src/StringUtils.cpp | |
parent | Fixed switch-ups regarding some slab and stair recipes (#5099) (diff) | |
download | cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.tar cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.tar.gz cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.tar.bz2 cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.tar.lz cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.tar.xz cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.tar.zst cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.zip |
Diffstat (limited to 'src/StringUtils.cpp')
-rw-r--r-- | src/StringUtils.cpp | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index e6fbcc6fe..c55456e24 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -972,10 +972,12 @@ AString Base64Encode(const AString & a_Input) -short GetBEShort(const char * a_Mem) +short GetBEShort(const std::byte * const a_Mem) { - const Byte * Bytes = reinterpret_cast<const Byte *>(a_Mem); - return static_cast<short>((Bytes[0] << 8) | Bytes[1]); + return static_cast<short>( + (static_cast<short>(a_Mem[0]) << 8) | + static_cast<short>(a_Mem[1]) + ); } @@ -992,22 +994,26 @@ unsigned short GetBEUShort(const char * a_Mem) -int GetBEInt(const char * a_Mem) +int GetBEInt(const std::byte * const a_Mem) { - const Byte * Bytes = reinterpret_cast<const Byte *>(a_Mem); - return (Bytes[0] << 24) | (Bytes[1] << 16) | (Bytes[2] << 8) | Bytes[3]; + return + (static_cast<int>(a_Mem[0]) << 24) | + (static_cast<int>(a_Mem[1]) << 16) | + (static_cast<int>(a_Mem[2]) << 8) | + static_cast<int>(a_Mem[3]) + ; } -void SetBEInt(char * a_Mem, Int32 a_Value) +void SetBEInt(std::byte * a_Mem, Int32 a_Value) { - a_Mem[0] = a_Value >> 24; - a_Mem[1] = static_cast<char>((a_Value >> 16) & 0xff); - a_Mem[2] = static_cast<char>((a_Value >> 8) & 0xff); - a_Mem[3] = static_cast<char>(a_Value & 0xff); + a_Mem[0] = std::byte(a_Value >> 24); + a_Mem[1] = std::byte((a_Value >> 16) & 0xff); + a_Mem[2] = std::byte((a_Value >> 8) & 0xff); + a_Mem[3] = std::byte(a_Value & 0xff); } |