diff --git a/src/ripple/protocol/impl/b58_utils.h b/src/ripple/protocol/impl/b58_utils.h index 3ca3112416a..c3bb0c03750 100644 --- a/src/ripple/protocol/impl/b58_utils.h +++ b/src/ripple/protocol/impl/b58_utils.h @@ -122,6 +122,14 @@ inplace_bigint_mul(std::span a, std::uint64_t b) [[nodiscard]] inline std::uint64_t inplace_bigint_div_rem(std::span numerator, std::uint64_t divisor) { + if (numerator.size() == 0) + { + // should never happen, but if it does then it seems natural to define + // the a null set of numbers to be zero, so the remainder is also zero. + assert(0); + return 0; + } + auto to_u128 = [](std::uint64_t high, std::uint64_t low) -> unsigned __int128 { unsigned __int128 const high128 = high; @@ -134,11 +142,13 @@ inplace_bigint_div_rem(std::span numerator, std::uint64_t divisor) unsigned __int128 const denom128 = denom; unsigned __int128 const d = num / denom128; unsigned __int128 const r = num - (denom128 * d); + assert(d >> 64 == 0); + assert(r >> 64 == 0); return {static_cast(d), static_cast(r)}; }; std::uint64_t prev_rem = 0; - std::size_t const last_index = numerator.size() - 1; + int const last_index = numerator.size() - 1; std::tie(numerator[last_index], prev_rem) = div_rem(numerator[last_index], divisor); for (int i = last_index - 1; i >= 0; --i) diff --git a/src/ripple/protocol/impl/tokens.cpp b/src/ripple/protocol/impl/tokens.cpp index 4439780a527..a0396568c4c 100644 --- a/src/ripple/protocol/impl/tokens.cpp +++ b/src/ripple/protocol/impl/tokens.cpp @@ -27,6 +27,7 @@ #include +#include #include #include @@ -329,7 +330,7 @@ encodeBase58Token(TokenType type, void const* token, std::size_t size) // Lay the data out as // - buf[0] = static_cast>(type); + buf[0] = safe_cast>(type); if (size) std::memcpy(buf.data() + 1, token, size); checksum(buf.data() + 1 + size, buf.data(), 1 + size); @@ -348,7 +349,7 @@ decodeBase58Token(std::string const& s, TokenType type) return {}; // The type must match. - if (type != static_cast(static_cast(ret[0]))) + if (type != safe_cast(static_cast(ret[0]))) return {}; // And the checksum must as well.