blob: 4b541498b6a1a5710d85b845765ab8fb1116506c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
diff --git a/src/test/uint256_tests.cpp b/src/test/uint256_tests.cpp
index 127a343e58df17d2cc8a010764f87aee52ed55c0..2bc84fa437c3bb220c8d6157623645339edd7453 100644
--- a/src/test/uint256_tests.cpp
+++ b/src/test/uint256_tests.cpp
@@ -1,5 +1,5 @@
// Copyright (c) 2011-2016 The Bitcoin Core developers
-// Copyright (c) 2021 The Bitcoin developers
+// Copyright (c) 2021-2025 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <uint256.h>
@@ -21,6 +21,7 @@
#include <cstdio>
#include <iomanip>
#include <limits>
+#include <new> // for std::launder
#include <sstream>
#include <string>
@@ -349,12 +350,14 @@ BOOST_AUTO_TEST_CASE(methods) {
{
// Note: this pointer is to data on the stack and should not be freed!
uint256 *uninitialized = new (alignedPtr) uint256(uint256::Uninitialized); // explicitly does not initialize the data
+ BOOST_CHECK(uninitialized->data() == alignedPtr);
+ uninitialized->~uint256(); // end object lifetime immediately
+ alignedPtr = std::launder(alignedPtr);
unsigned uninitializedCtr = 0;
// ensure the uninitialized c'tor left the data buffer unmolested
- for (const auto ch : *uninitialized) {
- uninitializedCtr += unsigned(ch == uninitializedByte); // false = 0, true = 1
+ for (size_t i = 0; i < uint256::size(); ++i) {
+ uninitializedCtr += unsigned(alignedPtr[i] == uninitializedByte); // false = 0, true = 1
}
- uninitialized->~uint256(); // end object lifetime politely
BOOST_CHECK(uninitializedCtr == uint256::size());
}
#if defined(__GNUC__) && !defined(__clang__)
|