Skip to content

Commit 92a71f6

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#24059: Fix implicit-integer-sign-change in arith_uint256
fa99e10 Fix implicit-integer-sign-change in arith_uint256 (MarcoFalke) Pull request description: This refactor doesn't change behaviour, but clarifies that the numbers being dealt with aren't supposed to be negative. This helps when reading the code and allows to remove a sanitizer suppression for the whole file. ACKs for top commit: PastaPastaPasta: utACK fa99e10 shaavan: ACK fa99e10 Tree-SHA512: f227e2fd22021e39f0445ec041f4a299d13477c23cef0fc06c53fb3313cbe550cec329336224a7e8775d9045b8009423052b394e83d42a1e40772085dfcdd471
2 parents dfe1341 + fa99e10 commit 92a71f6

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/arith_uint256.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ base_uint<BITS>& base_uint<BITS>::operator/=(const base_uint& b)
9696
while (shift >= 0) {
9797
if (num >= div) {
9898
num -= div;
99-
pn[shift / 32] |= (1 << (shift & 31)); // set a bit of the result.
99+
pn[shift / 32] |= (1U << (shift & 31)); // set a bit of the result.
100100
}
101101
div >>= 1; // shift back.
102102
shift--;
@@ -236,7 +236,7 @@ uint32_t arith_uint256::GetCompact(bool fNegative) const
236236
nCompact >>= 8;
237237
nSize++;
238238
}
239-
assert((nCompact & ~0x007fffff) == 0);
239+
assert((nCompact & ~0x007fffffU) == 0);
240240
assert(nSize < 256);
241241
nCompact |= nSize << 24;
242242
nCompact |= (fNegative && (nCompact & 0x007fffff) ? 0x00800000 : 0);

test/sanitizer_suppressions/ubsan

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ unsigned-integer-overflow:txmempool.cpp
6262
unsigned-integer-overflow:util/strencodings.cpp
6363
unsigned-integer-overflow:validation.cpp
6464
implicit-integer-sign-change:addrman.h
65-
implicit-integer-sign-change:arith_uint256.cpp
6665
implicit-integer-sign-change:bech32.cpp
6766
implicit-integer-sign-change:common/bloom.cpp
6867
implicit-integer-sign-change:chain.cpp

0 commit comments

Comments
 (0)