Skip to content

Commit

Permalink
Bugfix: use INT64_MAX instead of UINT64_MAX
Browse files Browse the repository at this point in the history
  • Loading branch information
JBetz committed Apr 23, 2024
1 parent bb65deb commit dcb2482
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/exchangerates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,33 @@

#include <fstream>

int64_t INT64_MAX_LIMIT = std::numeric_limits<int64_t>::max();

CAmount ExchangeRateMap::CalculateExchangeValue(const CAmount& amount, const CAsset& asset) {
auto it = this->find(asset);
if (it == this->end()) {
return 0;
}
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;
}
}

Expand Down

0 comments on commit dcb2482

Please sign in to comment.