From dcb24824ebea91145e97538f69fe6df93eec81a3 Mon Sep 17 00:00:00 2001 From: JBetz Date: Tue, 23 Apr 2024 15:39:12 +0200 Subject: [PATCH] Bugfix: use INT64_MAX instead of UINT64_MAX --- src/exchangerates.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/exchangerates.cpp b/src/exchangerates.cpp index 9c68bd7a97..6767490001 100644 --- a/src/exchangerates.cpp +++ b/src/exchangerates.cpp @@ -7,6 +7,8 @@ #include +int64_t INT64_MAX_LIMIT = std::numeric_limits::max(); + CAmount ExchangeRateMap::CalculateExchangeValue(const CAmount& amount, const CAsset& asset) { auto it = this->find(asset); if (it == this->end()) { @@ -14,24 +16,24 @@ 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; + if (value > INT64_MAX_LIMIT) { + return INT64_MAX_LIMIT; } else { - return (uint64_t) value; + return (int64_t) value; } } CAmount ExchangeRateMap::CalculateExchangeAmount(const CAmount& value, const CAsset& asset) { auto it = this->find(asset); if (it == this->end()) { - return UINT64_MAX; + return INT64_MAX_LIMIT; } auto scaled_value = it->second.m_scaled_value; __uint128_t amount = ((__uint128_t)value * (__uint128_t)exchange_rate_scale) / (__uint128_t)scaled_value; - if (value > UINT64_MAX) { - return UINT64_MAX; + if (value > INT64_MAX_LIMIT) { + return INT64_MAX_LIMIT; } else { - return (uint64_t) amount; + return (int64_t) amount; } }