feefrac test: avoid integer overflow (bugfix)

This commit is contained in:
Pieter Wuille 2025-04-08 15:18:03 -04:00
parent cfe025ff0e
commit a2bc330da8

View file

@ -220,9 +220,9 @@ FUZZ_TARGET(feefrac_mul_div)
assert(res == res_fee); assert(res == res_fee);
// Compare approximately with CFeeRate. // Compare approximately with CFeeRate.
if (mul64 <= std::numeric_limits<int64_t>::max() / 1000 && if (mul64 < std::numeric_limits<int64_t>::max() / 1000 &&
mul64 >= std::numeric_limits<int64_t>::min() / 1000 && mul64 > std::numeric_limits<int64_t>::min() / 1000 &&
quot_abs <= arith_uint256{std::numeric_limits<int64_t>::max() / 1000}) { quot_abs < arith_uint256{std::numeric_limits<int64_t>::max() / 1000}) {
CFeeRate feerate(mul64, (uint32_t)div); CFeeRate feerate(mul64, (uint32_t)div);
CAmount feerate_fee{feerate.GetFee(mul32)}; CAmount feerate_fee{feerate.GetFee(mul32)};
auto allowed_gap = static_cast<int64_t>(mul32 / 1000 + 3 + round_down); auto allowed_gap = static_cast<int64_t>(mul32 / 1000 + 3 + round_down);