Skip to content

Commit 88d8b4e

Browse files
author
MarcoFalke
committed
Merge #18901: fuzz: use std::optional for sep_pos_opt variable
420fa07 fuzz: use std::optional for sep_pos variable (Harris) Pull request description: This PR changes the original `size_t sep_pos` to `std::optional<size_t> sep_post_opt` to remove the warning when compiling fuzz tests. ```shell warning: variable 'sep_pos' may be uninitialized when used here [-Wconditional-uninitialized] ``` Also, it adds `--enable-c++17` flag to CI fuzz scripts. ACKs for top commit: practicalswift: ACK 420fa07 MarcoFalke: ACK 420fa07 Tree-SHA512: e967d5d8ab8ee7394b243ff5b28bac72d30bd14774e4a206f8c87474fad22769da76e4ba4e03cbef83b8f60e5293e9d9293b613e2e2e59e187d4e59ae6b874ca
2 parents 376294c + 420fa07 commit 88d8b4e

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

ci/test/00_setup_env_native_fuzz.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ export RUN_UNIT_TESTS=false
1414
export RUN_FUNCTIONAL_TESTS=false
1515
export RUN_FUZZ_TESTS=true
1616
export GOAL="install"
17-
export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,address,undefined CC=clang CXX=clang++"
17+
export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,address,undefined --enable-c++17 CC=clang CXX=clang++"

ci/test/00_setup_env_native_fuzz_with_valgrind.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ export RUN_FUNCTIONAL_TESTS=false
1515
export RUN_FUZZ_TESTS=true
1616
export FUZZ_TESTS_CONFIG="--valgrind"
1717
export GOAL="install"
18-
export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer CC=clang CXX=clang++"
18+
export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer --enable-c++17 CC=clang CXX=clang++"

src/test/fuzz/asmap_direct.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@
66
#include <test/fuzz/fuzz.h>
77

88
#include <cstdint>
9+
#include <optional>
910
#include <vector>
1011

1112
#include <assert.h>
1213

1314
void test_one_input(const std::vector<uint8_t>& buffer)
1415
{
1516
// Encoding: [asmap using 1 bit / byte] 0xFF [addr using 1 bit / byte]
16-
bool have_sep = false;
17-
size_t sep_pos;
17+
std::optional<size_t> sep_pos_opt;
1818
for (size_t pos = 0; pos < buffer.size(); ++pos) {
1919
uint8_t x = buffer[pos];
2020
if ((x & 0xFE) == 0) continue;
2121
if (x == 0xFF) {
22-
if (have_sep) return;
23-
have_sep = true;
24-
sep_pos = pos;
22+
if (sep_pos_opt) return;
23+
sep_pos_opt = pos;
2524
} else {
2625
return;
2726
}
2827
}
29-
if (!have_sep) return; // Needs exactly 1 separator
28+
if (!sep_pos_opt) return; // Needs exactly 1 separator
29+
const size_t sep_pos{sep_pos_opt.value()};
3030
if (buffer.size() - sep_pos - 1 > 128) return; // At most 128 bits in IP address
3131

3232
// Checks on asmap

0 commit comments

Comments
 (0)