Bitcoin Core  27.99.0
P2P Digital Currency
spanparsing.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2020 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
6 #include <test/fuzz/fuzz.h>
7 #include <util/spanparsing.h>
8 
10 {
11  FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
12  const size_t query_size = fuzzed_data_provider.ConsumeIntegral<size_t>();
13  const std::string query = fuzzed_data_provider.ConsumeBytesAsString(std::min<size_t>(query_size, 1024 * 1024));
14  const std::string span_str = fuzzed_data_provider.ConsumeRemainingBytesAsString();
15  const Span<const char> const_span{span_str};
16 
17  Span<const char> mut_span = const_span;
18  (void)spanparsing::Const(query, mut_span);
19 
20  mut_span = const_span;
21  (void)spanparsing::Func(query, mut_span);
22 
23  mut_span = const_span;
24  (void)spanparsing::Expr(mut_span);
25 
26  if (!query.empty()) {
27  mut_span = const_span;
28  (void)spanparsing::Split(mut_span, query.front());
29  }
30 }
std::string ConsumeBytesAsString(size_t num_bytes)
std::string ConsumeRemainingBytesAsString()
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:98
CONSTEXPR_IF_NOT_DEBUG C & front() const noexcept
Definition: span.h:177
Span< const char > Expr(Span< const char > &sp)
Extract the expression that sp begins with.
Definition: spanparsing.cpp:33
bool Const(const std::string &str, Span< const char > &sp)
Parse a constant.
Definition: spanparsing.cpp:15
bool Func(const std::string &str, Span< const char > &sp)
Parse a function call.
Definition: spanparsing.cpp:24
std::vector< T > Split(const Span< const char > &sp, std::string_view separators)
Split a string on any char found in separators, returning a vector.
Definition: spanparsing.h:48
FUZZ_TARGET(spanparsing)
Definition: spanparsing.cpp:9