Skip to content

Commit 219d728

Browse files
author
MarcoFalke
committed
Merge bitcoin#24219: Fix implicit-integer-sign-change in bloom
fad84a2 refactor: Fixup uint64_t-cast style in touched line (MarcoFalke) fa04187 Fix implicit-integer-sign-change in bloom (MarcoFalke) Pull request description: Signed values don't really make sense when using `std::vector::operator[]`. Fix that and remove the suppression. ACKs for top commit: PastaPastaPasta: utACK fad84a2 theStack: Code-review ACK fad84a2 Tree-SHA512: 7139dd9aa098c41e4af1b6e63dd80e71a92b0a98062d1676b01fe550ffa8e21a5f84a578afa7a536d70dad1b8a5017625e3a9e2dda6f864b452ec77b130ddf2a
2 parents a41976a + fad84a2 commit 219d728

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

src/common/bloom.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ void CRollingBloomFilter::insert(Span<const unsigned char> vKey)
218218
/* FastMod works with the upper bits of h, so it is safe to ignore that the lower bits of h are already used for bit. */
219219
uint32_t pos = FastRange32(h, data.size());
220220
/* The lowest bit of pos is ignored, and set to zero for the first bit, and to one for the second. */
221-
data[pos & ~1] = (data[pos & ~1] & ~(((uint64_t)1) << bit)) | ((uint64_t)(nGeneration & 1)) << bit;
222-
data[pos | 1] = (data[pos | 1] & ~(((uint64_t)1) << bit)) | ((uint64_t)(nGeneration >> 1)) << bit;
221+
data[pos & ~1U] = (data[pos & ~1U] & ~(uint64_t{1} << bit)) | (uint64_t(nGeneration & 1)) << bit;
222+
data[pos | 1] = (data[pos | 1] & ~(uint64_t{1} << bit)) | (uint64_t(nGeneration >> 1)) << bit;
223223
}
224224
}
225225

@@ -230,7 +230,7 @@ bool CRollingBloomFilter::contains(Span<const unsigned char> vKey) const
230230
int bit = h & 0x3F;
231231
uint32_t pos = FastRange32(h, data.size());
232232
/* If the relevant bit is not set in either data[pos & ~1] or data[pos | 1], the filter does not contain vKey */
233-
if (!(((data[pos & ~1] | data[pos | 1]) >> bit) & 1)) {
233+
if (!(((data[pos & ~1U] | data[pos | 1]) >> bit) & 1)) {
234234
return false;
235235
}
236236
}

test/sanitizer_suppressions/ubsan

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ unsigned-integer-overflow:util/strencodings.cpp
6060
unsigned-integer-overflow:validation.cpp
6161
implicit-integer-sign-change:addrman.h
6262
implicit-integer-sign-change:bech32.cpp
63-
implicit-integer-sign-change:common/bloom.cpp
6463
implicit-integer-sign-change:coins.h
6564
implicit-integer-sign-change:compat/stdin.cpp
6665
implicit-integer-sign-change:compressor.h

0 commit comments

Comments
 (0)