Skip to content

Commit

Permalink
fuzz: use std::optional for sep_pos variable
Browse files Browse the repository at this point in the history
Summary:
```
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.
```

Backport of core [[bitcoin/bitcoin#18901 | PR18901]].

Note that we don't have the warning for some reason.

Test Plan:
  ninja bitcoin-fuzzers
  ./src/test/fuzz/asmap_direct <path_to_corpus>

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Differential Revision: https://reviews.bitcoinabc.org/D9060
  • Loading branch information
brakmic authored and Fabcien committed Jan 26, 2021
1 parent eb81b06 commit 04e0fd2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/test/fuzz/asmap_direct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@

#include <cassert>
#include <cstdint>
#include <optional>
#include <vector>

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) {
if (sep_pos_opt) {
return;
}
have_sep = true;
sep_pos = pos;
sep_pos_opt = pos;
} else {
return;
}
}
if (!have_sep) {
if (!sep_pos_opt) {
// Needs exactly 1 separator
return;
}
const size_t sep_pos{sep_pos_opt.value()};
if (buffer.size() - sep_pos - 1 > 128) {
// At most 128 bits in IP address
return;
Expand Down

0 comments on commit 04e0fd2

Please sign in to comment.