test: Redeclare variable as signed in `util_tests`
What changed, and why it matters
This is a minor fix to a unit test file. A test variable was being assigned a negative value in an unsigned container, which caused a silent underflow and made the test assertion technically incorrect. The patch changes the test to check the negative result directly without storing it in the wrong type. It does not change any production code or affect real Bitcoin Core behavior.
No security action required. This is a test-only correctness cleanup. Reviewers may optionally verify that other tests do not rely on similar unsigned/signed mismatches.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In src/test/util_tests.cpp, the test_ToIntegralHex case used an optional<uint64_t> n to receive the result of ToIntegral<int64_t>("-1", 16). Assigning a signed -1 to an unsigned 64-bit optional silently underflows to 0xFFFFFFFFFFFFFFFF. The subsequent BOOST_CHECK_EQUAL(*n, -1) then promotes the literal -1 to uint64_t, also underflowing, so the comparison happened to pass by accident. The patch removes the assignment and instead performs the check inline: BOOST_CHECK_EQUAL(*ToIntegral<int64_t>("-1", 16), -1), using the correct signed type. No production code is modified.
Changed components
src/test/util_tests.cppInspect captured patch +1 / −2
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp
index e26234f8..6eddd362 100644
--- a/src/test/util_tests.cpp
+++ b/src/test/util_tests.cpp
@@ -883,8 +883,7 @@ BOOST_AUTO_TEST_CASE(test_ToIntegralHex)
BOOST_CHECK_EQUAL(*n, 0);
n = ToIntegral<uint64_t>("FfFfFfFfFfFfFfFf", 16);
BOOST_CHECK_EQUAL(*n, 0xFfFfFfFfFfFfFfFfULL);
- n = ToIntegral<int64_t>("-1", 16);
- BOOST_CHECK_EQUAL(*n, -1);
+ BOOST_CHECK_EQUAL(*ToIntegral<int64_t>("-1", 16), -1);
// Invalid values
BOOST_CHECK(!ToIntegral<uint64_t>("", 16));
BOOST_CHECK(!ToIntegral<uint64_t>("-1", 16));
Why this scored 15/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.