diff --git a/src/test/fuzz/asmap_direct.cpp b/src/test/fuzz/asmap_direct.cpp index 2dcfb6054..f8a8dd94a 100644 --- a/src/test/fuzz/asmap_direct.cpp +++ b/src/test/fuzz/asmap_direct.cpp @@ -1,61 +1,61 @@ // Copyright (c) 2020 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include #include +#include #include void test_one_input(const std::vector &buffer) { // Encoding: [asmap using 1 bit / byte] 0xFF [addr using 1 bit / byte] - bool have_sep = false; - size_t sep_pos; + std::optional 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; } // Checks on asmap std::vector asmap(buffer.begin(), buffer.begin() + sep_pos); if (SanityCheckASMap(asmap, buffer.size() - 1 - sep_pos)) { // Verify that for valid asmaps, no prefix (except up to 7 zero padding // bits) is valid. std::vector asmap_prefix = asmap; while (!asmap_prefix.empty() && asmap_prefix.size() + 7 > asmap.size() && asmap_prefix.back() == false) { asmap_prefix.pop_back(); } while (!asmap_prefix.empty()) { asmap_prefix.pop_back(); assert( !SanityCheckASMap(asmap_prefix, buffer.size() - 1 - sep_pos)); } // No address input should trigger assertions in interpreter std::vector addr(buffer.begin() + sep_pos + 1, buffer.end()); (void)Interpret(asmap, addr); } }