diff --git a/deps/ox/src/ox/mc/intops.hpp b/deps/ox/src/ox/mc/intops.hpp index 1762e8d3..b6e6ac6a 100644 --- a/deps/ox/src/ox/mc/intops.hpp +++ b/deps/ox/src/ox/mc/intops.hpp @@ -10,6 +10,7 @@ #include #include +#include namespace ox::mc { @@ -117,12 +118,15 @@ static_assert(countBytes(0b01111111) == 8); static_assert(countBytes(0b11111111) == 9); template -[[nodiscard]] ValErr decodeInteger(uint8_t buff[9], std::size_t buffLen) noexcept { +[[nodiscard]] ValErr decodeInteger(uint8_t buff[9], std::size_t buffLen, std::size_t *bytesRead) noexcept { const auto bytes = countBytes(buff[0]); if (bytes == 9) { + *bytesRead = bytes; return {LittleEndian(*reinterpret_cast(&buff[1])), 0}; } else if (buffLen >= bytes) { - uint64_t decoded = LittleEndian(*reinterpret_cast(&buff[0])); + *bytesRead = bytes; + uint64_t decoded = 0; + ox_memcpy(&decoded, &buff[0], bytes); decoded >>= bytes; auto out = static_cast(decoded); // move sign bit @@ -142,7 +146,8 @@ template template [[nodiscard]] ValErr decodeInteger(McInt m) noexcept { - return decodeInteger(m.data, 9); + std::size_t bytesRead; + return decodeInteger(m.data, 9, &bytesRead); } }