Skip to content

Commit 5cb1241

Browse files
committed
feefrac: avoid integer overflow in temporary
1 parent bfeacc1 commit 5cb1241

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/test/feefrac_tests.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ BOOST_AUTO_TEST_CASE(feefrac_operators)
148148
FeeFrac max_fee2{1, 1};
149149
BOOST_CHECK(max_fee >= max_fee2);
150150

151+
// Test for integer overflow issue (https://github.com/bitcoin/bitcoin/issues/32294)
152+
BOOST_CHECK_EQUAL((FeeFrac{0x7ffffffdfffffffb, 0x7ffffffd}.EvaluateFeeDown(0x7fffffff)), 0x7fffffffffffffff);
151153
}
152154

153155
BOOST_AUTO_TEST_SUITE_END()

src/util/feefrac.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ struct FeeFrac
9696
int64_t quot = n / d;
9797
int32_t mod = n % d;
9898
// Correct result if the / operator above rounded in the wrong direction.
99-
return quot + (mod > 0) - (mod && round_down);
99+
return quot + ((mod > 0) - (mod && round_down));
100100
}
101101
#else
102102
static constexpr auto Mul = MulFallback;

0 commit comments

Comments
 (0)