mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Merge #18901: fuzz: use std::optional for sep_pos_opt variable
420fa0770f37619bfa29898d59dac45b6a477abb 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 420fa0770f37619bfa29898d59dac45b6a477abb MarcoFalke: ACK 420fa07 Tree-SHA512: e967d5d8ab8ee7394b243ff5b28bac72d30bd14774e4a206f8c87474fad22769da76e4ba4e03cbef83b8f60e5293e9d9293b613e2e2e59e187d4e59ae6b874ca
This commit is contained in:
parent
1f49424788
commit
b87625d738
@ -15,4 +15,4 @@ export RUN_UNIT_TESTS=false
|
|||||||
export RUN_INTEGRATION_TESTS=false
|
export RUN_INTEGRATION_TESTS=false
|
||||||
export RUN_FUZZ_TESTS=true
|
export RUN_FUZZ_TESTS=true
|
||||||
export GOAL="install"
|
export GOAL="install"
|
||||||
export BITCOIN_CONFIG="--enable-zmq --disable-ccache --enable-fuzz --with-sanitizers=fuzzer,address,undefined CC=clang CXX=clang++"
|
export BITCOIN_CONFIG="--enable-zmq --disable-ccache --enable-fuzz --with-sanitizers=fuzzer,address,undefined --enable-c++17 CC=clang CXX=clang++"
|
||||||
|
@ -14,5 +14,5 @@ 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-8 CXX=clang++-8"
|
export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer --enable-c++17 CC=clang-8 CXX=clang++-8"
|
||||||
# Use clang-8, instead of default clang on bionic, which is clang-6 and does not come with libfuzzer on aarch64
|
# Use clang-8, instead of default clang on bionic, which is clang-6 and does not come with libfuzzer on aarch64
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <test/fuzz/fuzz.h>
|
#include <test/fuzz/fuzz.h>
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -14,20 +15,19 @@
|
|||||||
FUZZ_TARGET(asmap_direct)
|
FUZZ_TARGET(asmap_direct)
|
||||||
{
|
{
|
||||||
// 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 New Issue
Block a user