Bitcoin Core  22.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 }
FuzzedDataProvider::ConsumeRemainingBytesAsString
std::string ConsumeRemainingBytesAsString()
Definition: FuzzedDataProvider.h:187
FUZZ_TARGET
FUZZ_TARGET(spanparsing)
Definition: spanparsing.cpp:9
spanparsing::Split
std::vector< Span< const char > > Split(const Span< const char > &sp, char sep)
Split a string on every instance of sep, returning a vector.
Definition: spanparsing.cpp:51
spanparsing::Func
bool Func(const std::string &str, Span< const char > &sp)
Parse a function call.
Definition: spanparsing.cpp:23
Span
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:92
FuzzedDataProvider.h
spanparsing.h
spanparsing::Const
bool Const(const std::string &str, Span< const char > &sp)
Parse a constant.
Definition: spanparsing.cpp:14
Span::front
CONSTEXPR_IF_NOT_DEBUG C & front() const noexcept
Definition: span.h:172
fuzz.h
FuzzedDataProvider
Definition: FuzzedDataProvider.h:31
FuzzedDataProvider::ConsumeIntegral
T ConsumeIntegral()
Definition: FuzzedDataProvider.h:194
spanparsing::Expr
Span< const char > Expr(Span< const char > &sp)
Extract the expression that sp begins with.
Definition: spanparsing.cpp:32
FuzzedDataProvider::ConsumeBytesAsString
std::string ConsumeBytesAsString(size_t num_bytes)
Definition: FuzzedDataProvider.h:136
spanparsing
Definition: spanparsing.cpp:12