uint256: Workaround GCC-14 stringop-overread bug in Compare
What changed, and why it matters
This is a compiler-specific workaround, not a fix for a security vulnerability in Bitcoin Core itself. The change swaps a low-level memory comparison for a C++ standard-library comparison in a 256-bit integer class, solely to silence a false-positive warning produced by GCC 14. There is no indication it changes runtime behavior or fixes an exploitable bug.
No security action required. Treat as a normal build-compatibility cleanup. If backporting, do so only to resolve GCC 14 build warnings, not for a security fix.
Security signals we found
Commit title references a compiler bug, not a product vulnerability
Change is a functional equivalent rewrite of a comparison routine
No input validation, memory allocation, or cryptographic path is modified
No advisory, CVE, or security release language in commit message
Evidence from the diff
The commit replaces std::memcmp with the C++20 three-way comparison operator (<=>) on std::array members inside base_blob::Compare. The stated reason is to work around a GCC-14 stringop-overread false positive. The function remains constexpr, returns the same -1/0/1 semantics, and the generated comparison logic is equivalent for the fixed-size WIDTH byte array. No bounds issue exists in the original code because m_data is a std::array<uint8_t, WIDTH> and WIDTH matches its exact size.
Changed components
src/uint256.hbase_blob::Compareuint256/uint160 comparison operatorsInspect captured patch +7 / −1
diff --git a/src/uint256.h b/src/uint256.h
index 3fe44ab7..1419fd79 100644
--- a/src/uint256.h
+++ b/src/uint256.h
@@ -15,6 +15,7 @@
#include <algorithm>
#include <array>
#include <cassert>
+#include <compare>
#include <cstdint>
#include <cstring>
#include <optional>
@@ -62,7 +63,12 @@ public:
* @note Does NOT match the ordering on the corresponding \ref
* base_uint::CompareTo, which starts comparing from the end.
*/
- constexpr int Compare(const base_blob& other) const { return std::memcmp(m_data.data(), other.m_data.data(), WIDTH); }
+ constexpr int Compare(const base_blob& other) const {
+ auto cmp = m_data <=> other.m_data;
+ if (cmp < 0) return -1;
+ if (cmp > 0) return 1;
+ return 0;
+ }
friend constexpr bool operator==(const base_blob& a, const base_blob& b) { return a.Compare(b) == 0; }
friend constexpr bool operator<(const base_blob& a, const base_blob& b) { return a.Compare(b) < 0; }
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.