Skip to content

Commit

Permalink
Use INT64_MAX instead of UINT64_MAX for overflow checks
Browse files Browse the repository at this point in the history
  • Loading branch information
JBetz committed Apr 24, 2024
1 parent d3911fd commit 8d64eb8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/exchangerates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int64_t>::max();
if (value > int64_max) {
return int64_max;
} else {
return (uint64_t) value;
return (int64_t) value;
}
}

Expand Down

0 comments on commit 8d64eb8

Please sign in to comment.