Skip to content

Commit 57a1e73

Browse files
committed
fix: gcc-11 workaround for memcmp in uint256 class
This workaround let enable -Werror -Wall on our CI In member function ‘constexpr int base_blob<BITS>::Compare(const base_blob<BITS>&) const [with unsigned int BITS = 256]’, inlined from ‘constexpr bool operator!=(const base_blob<256>&, const base_blob<256>&)’ at ./uint256.h:58:96, inlined from ‘bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock&, gsl::not_null<const CBlockIndex*>, BlockValidationState&, const CCoinsViewCache&, CDeterministicMNList&, llmq::CQuorumSnapshotManager&, bool)’ at evo/deterministicmns.cpp:818:119: ./uint256.h:55:77: error: ‘int __builtin_memcmp_eq(const void*, const void*, long unsigned int)’ specified bound 32 exceeds source size 0 [-Werror=stringop-overread] 55 | constexpr int Compare(const base_blob& other) const { return std::memcmp(m_data.data(), other.m_data.data(), WIDTH); } | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1plus: all warnings being treated as errors
1 parent 8af10d7 commit 57a1e73

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/uint256.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,19 @@ class base_blob
5252
std::fill(m_data.begin(), m_data.end(), 0);
5353
}
5454

55-
constexpr int Compare(const base_blob& other) const { return std::memcmp(m_data.data(), other.m_data.data(), WIDTH); }
55+
// TODO: remove this gcc-11 workaround for memcmp
56+
// gcc-11 can not recognise size of internal data in std::array even if width is not zero and show this warning:
57+
// error: ‘int __builtin_memcmp_eq(const void*, const void*, long unsigned int)’ specified bound 32 exceeds source size 0 [-Werror=stringop-overread]
58+
#if (defined __GNUC__) && (__GNUC__ < 12)
59+
#pragma GCC diagnostic push
60+
#pragma GCC diagnostic ignored "-Wstringop-overread"
61+
#endif
62+
constexpr int Compare(const base_blob& other) const {
63+
return std::memcmp(m_data.data(), other.m_data.data(), WIDTH);
64+
}
65+
#if (defined __GNUC__) && (__GNUC__ < 12)
66+
#pragma GCC diagnostic pop
67+
#endif
5668

5769
friend constexpr bool operator==(const base_blob& a, const base_blob& b) { return a.Compare(b) == 0; }
5870
friend constexpr bool operator!=(const base_blob& a, const base_blob& b) { return a.Compare(b) != 0; }

0 commit comments

Comments
 (0)