fuzz: use std::optional for sep_pos variable
Co-authored-by: MarcoFalke <falke.marco@gmail.com>
This commit is contained in:
parent
b55866969e
commit
420fa0770f
3 changed files with 8 additions and 8 deletions
|
@ -14,4 +14,4 @@ export RUN_UNIT_TESTS=false
|
||||||
export RUN_FUNCTIONAL_TESTS=false
|
export RUN_FUNCTIONAL_TESTS=false
|
||||||
export RUN_FUZZ_TESTS=true
|
export RUN_FUZZ_TESTS=true
|
||||||
export GOAL="install"
|
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++"
|
||||||
|
|
|
@ -15,4 +15,4 @@ export RUN_FUNCTIONAL_TESTS=false
|
||||||
export RUN_FUZZ_TESTS=true
|
export RUN_FUZZ_TESTS=true
|
||||||
export FUZZ_TESTS_CONFIG="--valgrind"
|
export FUZZ_TESTS_CONFIG="--valgrind"
|
||||||
export GOAL="install"
|
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++"
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <test/fuzz/fuzz.h>
|
#include <test/fuzz/fuzz.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -13,20 +14,19 @@
|
||||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||||
{
|
{
|
||||||
// Encoding: [asmap using 1 bit / byte] 0xFF [addr using 1 bit / byte]
|
// Encoding: [asmap using 1 bit / byte] 0xFF [addr using 1 bit / byte]
|
||||||
bool have_sep = false;
|
std::optional<size_t> sep_pos_opt;
|
||||||
size_t sep_pos;
|
|
||||||
for (size_t pos = 0; pos < buffer.size(); ++pos) {
|
for (size_t pos = 0; pos < buffer.size(); ++pos) {
|
||||||
uint8_t x = buffer[pos];
|
uint8_t x = buffer[pos];
|
||||||
if ((x & 0xFE) == 0) continue;
|
if ((x & 0xFE) == 0) continue;
|
||||||
if (x == 0xFF) {
|
if (x == 0xFF) {
|
||||||
if (have_sep) return;
|
if (sep_pos_opt) return;
|
||||||
have_sep = true;
|
sep_pos_opt = pos;
|
||||||
sep_pos = pos;
|
|
||||||
} else {
|
} else {
|
||||||
return;
|
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
|
if (buffer.size() - sep_pos - 1 > 128) return; // At most 128 bits in IP address
|
||||||
|
|
||||||
// Checks on asmap
|
// Checks on asmap
|
||||||
|
|
Loading…
Reference in a new issue