aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarris <brakmic@gmail.com>2020-05-09 11:09:52 +0200
committerHarris <brakmic@gmail.com>2020-05-09 11:09:52 +0200
commit420fa0770f37619bfa29898d59dac45b6a477abb (patch)
tree374e4e73842a177b43f13ef9cc5e4b531296e13a
parentb55866969e248cbd912a1c298e3ba375685575dc (diff)
downloadbitcoin-420fa0770f37619bfa29898d59dac45b6a477abb.tar.xz
fuzz: use std::optional for sep_pos variable
Co-authored-by: MarcoFalke <falke.marco@gmail.com>
-rw-r--r--ci/test/00_setup_env_native_fuzz.sh2
-rw-r--r--ci/test/00_setup_env_native_fuzz_with_valgrind.sh2
-rw-r--r--src/test/fuzz/asmap_direct.cpp12
3 files changed, 8 insertions, 8 deletions
diff --git a/ci/test/00_setup_env_native_fuzz.sh b/ci/test/00_setup_env_native_fuzz.sh
index 43ee219ef9..f51cbf8f3c 100644
--- a/ci/test/00_setup_env_native_fuzz.sh
+++ b/ci/test/00_setup_env_native_fuzz.sh
@@ -14,4 +14,4 @@ export RUN_UNIT_TESTS=false
export RUN_FUNCTIONAL_TESTS=false
export RUN_FUZZ_TESTS=true
export GOAL="install"
-export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,address,undefined CC=clang CXX=clang++"
+export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,address,undefined --enable-c++17 CC=clang CXX=clang++"
diff --git a/ci/test/00_setup_env_native_fuzz_with_valgrind.sh b/ci/test/00_setup_env_native_fuzz_with_valgrind.sh
index c27d525003..fb4c27c36f 100644
--- a/ci/test/00_setup_env_native_fuzz_with_valgrind.sh
+++ b/ci/test/00_setup_env_native_fuzz_with_valgrind.sh
@@ -15,4 +15,4 @@ export RUN_FUNCTIONAL_TESTS=false
export RUN_FUZZ_TESTS=true
export FUZZ_TESTS_CONFIG="--valgrind"
export GOAL="install"
-export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer CC=clang CXX=clang++"
+export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer --enable-c++17 CC=clang CXX=clang++"
diff --git a/src/test/fuzz/asmap_direct.cpp b/src/test/fuzz/asmap_direct.cpp
index 790f80237d..6d8a65f5ab 100644
--- a/src/test/fuzz/asmap_direct.cpp
+++ b/src/test/fuzz/asmap_direct.cpp
@@ -6,6 +6,7 @@
#include <test/fuzz/fuzz.h>
#include <cstdint>
+#include <optional>
#include <vector>
#include <assert.h>
@@ -13,20 +14,19 @@
void test_one_input(const std::vector<uint8_t>& buffer)
{
// Encoding: [asmap using 1 bit / byte] 0xFF [addr using 1 bit / byte]
- bool have_sep = false;
- size_t sep_pos;
+ std::optional<size_t> sep_pos_opt;
for (size_t pos = 0; pos < buffer.size(); ++pos) {
uint8_t x = buffer[pos];
if ((x & 0xFE) == 0) continue;
if (x == 0xFF) {
- if (have_sep) return;
- have_sep = true;
- sep_pos = pos;
+ if (sep_pos_opt) return;
+ sep_pos_opt = pos;
} else {
return;
}
}
- if (!have_sep) return; // Needs exactly 1 separator
+ if (!sep_pos_opt) return; // Needs exactly 1 separator
+ const size_t sep_pos{sep_pos_opt.value()};
if (buffer.size() - sep_pos - 1 > 128) return; // At most 128 bits in IP address
// Checks on asmap