mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
feefrac: avoid integer overflow in temporary
This commit is contained in:
parent
bfeacc18b3
commit
5cb1241814
2 changed files with 3 additions and 1 deletions
|
@ -148,6 +148,8 @@ BOOST_AUTO_TEST_CASE(feefrac_operators)
|
|||
FeeFrac max_fee2{1, 1};
|
||||
BOOST_CHECK(max_fee >= max_fee2);
|
||||
|
||||
// Test for integer overflow issue (https://github.com/bitcoin/bitcoin/issues/32294)
|
||||
BOOST_CHECK_EQUAL((FeeFrac{0x7ffffffdfffffffb, 0x7ffffffd}.EvaluateFeeDown(0x7fffffff)), 0x7fffffffffffffff);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
|
|
@ -96,7 +96,7 @@ struct FeeFrac
|
|||
int64_t quot = n / d;
|
||||
int32_t mod = n % d;
|
||||
// Correct result if the / operator above rounded in the wrong direction.
|
||||
return quot + (mod > 0) - (mod && round_down);
|
||||
return quot + ((mod > 0) - (mod && round_down));
|
||||
}
|
||||
#else
|
||||
static constexpr auto Mul = MulFallback;
|
||||
|
|
Loading…
Add table
Reference in a new issue