From fa041878de786f5be74ec74a06ec407c99ca8656 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 31 Jan 2022 17:29:02 +0100 Subject: [PATCH 1/2] Fix implicit-integer-sign-change in bloom --- src/common/bloom.cpp | 4 ++-- test/sanitizer_suppressions/ubsan | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/common/bloom.cpp b/src/common/bloom.cpp index c744d05a0e1..7a3847620ee 100644 --- a/src/common/bloom.cpp +++ b/src/common/bloom.cpp @@ -218,7 +218,7 @@ void CRollingBloomFilter::insert(Span vKey) /* 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. */ uint32_t pos = FastRange32(h, data.size()); /* The lowest bit of pos is ignored, and set to zero for the first bit, and to one for the second. */ - data[pos & ~1] = (data[pos & ~1] & ~(((uint64_t)1) << bit)) | ((uint64_t)(nGeneration & 1)) << bit; + data[pos & ~1U] = (data[pos & ~1U] & ~(((uint64_t)1) << bit)) | ((uint64_t)(nGeneration & 1)) << bit; data[pos | 1] = (data[pos | 1] & ~(((uint64_t)1) << bit)) | ((uint64_t)(nGeneration >> 1)) << bit; } } @@ -230,7 +230,7 @@ bool CRollingBloomFilter::contains(Span vKey) const int bit = h & 0x3F; uint32_t pos = FastRange32(h, data.size()); /* If the relevant bit is not set in either data[pos & ~1] or data[pos | 1], the filter does not contain vKey */ - if (!(((data[pos & ~1] | data[pos | 1]) >> bit) & 1)) { + if (!(((data[pos & ~1U] | data[pos | 1]) >> bit) & 1)) { return false; } } diff --git a/test/sanitizer_suppressions/ubsan b/test/sanitizer_suppressions/ubsan index 07a440a2906..4ebcaf1a15e 100644 --- a/test/sanitizer_suppressions/ubsan +++ b/test/sanitizer_suppressions/ubsan @@ -60,7 +60,6 @@ unsigned-integer-overflow:util/strencodings.cpp unsigned-integer-overflow:validation.cpp implicit-integer-sign-change:addrman.h implicit-integer-sign-change:bech32.cpp -implicit-integer-sign-change:common/bloom.cpp implicit-integer-sign-change:coins.h implicit-integer-sign-change:compat/stdin.cpp implicit-integer-sign-change:compressor.h From fad84a25956ec081f22aebbda309d168a3dc0004 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Tue, 1 Feb 2022 11:20:05 +0100 Subject: [PATCH 2/2] refactor: Fixup uint64_t-cast style in touched line --- src/common/bloom.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/bloom.cpp b/src/common/bloom.cpp index 7a3847620ee..8b32a6c94a9 100644 --- a/src/common/bloom.cpp +++ b/src/common/bloom.cpp @@ -218,8 +218,8 @@ void CRollingBloomFilter::insert(Span vKey) /* 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. */ uint32_t pos = FastRange32(h, data.size()); /* The lowest bit of pos is ignored, and set to zero for the first bit, and to one for the second. */ - data[pos & ~1U] = (data[pos & ~1U] & ~(((uint64_t)1) << bit)) | ((uint64_t)(nGeneration & 1)) << bit; - data[pos | 1] = (data[pos | 1] & ~(((uint64_t)1) << bit)) | ((uint64_t)(nGeneration >> 1)) << bit; + data[pos & ~1U] = (data[pos & ~1U] & ~(uint64_t{1} << bit)) | (uint64_t(nGeneration & 1)) << bit; + data[pos | 1] = (data[pos | 1] & ~(uint64_t{1} << bit)) | (uint64_t(nGeneration >> 1)) << bit; } }