aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorJohn Newbery <john@johnnewbery.com>2021-08-25 13:30:17 +0100
committerJohn Newbery <john@johnnewbery.com>2021-08-27 11:01:45 +0100
commit724c4975622bc22cedc3f3814dfc8e66cf8371f7 (patch)
tree3473297b9f9b60aaa28b131a2af45a01e7df2114 /src/test
parent5840476714ffebb2599999c85a23b52ebcff6090 (diff)
[fuzz] Add ConsumeAsmap() function
Diffstat (limited to 'src/test')
-rw-r--r--src/test/fuzz/addrman.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/test/fuzz/addrman.cpp b/src/test/fuzz/addrman.cpp
index bc079451b4..e95126a80f 100644
--- a/src/test/fuzz/addrman.cpp
+++ b/src/test/fuzz/addrman.cpp
@@ -218,17 +218,18 @@ public:
}
};
+[[nodiscard]] inline std::vector<bool> ConsumeAsmap(FuzzedDataProvider& fuzzed_data_provider) noexcept
+{
+ std::vector<bool> asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
+ if (!SanityCheckASMap(asmap)) asmap.clear();
+ return asmap;
+}
+
FUZZ_TARGET_INIT(addrman, initialize_addrman)
{
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
SetMockTime(ConsumeTime(fuzzed_data_provider));
- std::vector<bool> asmap;
- if (fuzzed_data_provider.ConsumeBool()) {
- asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
- if (!SanityCheckASMap(asmap)) {
- asmap.clear();
- }
- }
+ std::vector<bool> asmap = ConsumeAsmap(fuzzed_data_provider);
auto addr_man_ptr = std::make_unique<CAddrManDeterministic>(asmap, fuzzed_data_provider);
if (fuzzed_data_provider.ConsumeBool()) {
const std::vector<uint8_t> serialized_data{ConsumeRandomLengthByteVector(fuzzed_data_provider)};
@@ -307,10 +308,7 @@ FUZZ_TARGET_INIT(addrman_serdeser, initialize_addrman)
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
SetMockTime(ConsumeTime(fuzzed_data_provider));
- std::vector<bool> asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
- if (!SanityCheckASMap(asmap)) {
- asmap.clear();
- }
+ std::vector<bool> asmap = ConsumeAsmap(fuzzed_data_provider);
CAddrManDeterministic addr_man1{asmap, fuzzed_data_provider};
CAddrManDeterministic addr_man2{asmap, fuzzed_data_provider};