Skip to content

Commit 420fa07

Browse files
brakmicMarcoFalke
andcommitted
fuzz: use std::optional for sep_pos variable
Co-authored-by: MarcoFalke <[email protected]>
1 parent b558669 commit 420fa07

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)