From 8d64eb8aa427ca1eab7b2423a4c9920ce4327b8f Mon Sep 17 00:00:00 2001 From: JBetz Date: Wed, 24 Apr 2024 04:43:14 +0200 Subject: [PATCH] Use INT64_MAX instead of UINT64_MAX for overflow checks --- src/exchangerates.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/exchangerates.cpp b/src/exchangerates.cpp index 039e7a66f0..c31f43319d 100644 --- a/src/exchangerates.cpp +++ b/src/exchangerates.cpp @@ -14,10 +14,11 @@ CAmount ExchangeRateMap::CalculateExchangeValue(const CAmount& amount, const CAs } auto scaled_value = it->second.m_scaled_value; __uint128_t value = ((__uint128_t)amount * (__uint128_t)scaled_value) / (__uint128_t)exchange_rate_scale; - if (value > UINT64_MAX) { - return UINT64_MAX; + int64_t int64_max = std::numeric_limits::max(); + if (value > int64_max) { + return int64_max; } else { - return (uint64_t) value; + return (int64_t) value; } }