Branch data Line data Source code
1 : : // Copyright (c) 2020-present 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 : :
5 : : #include <span.h>
6 : : #include <test/fuzz/FuzzedDataProvider.h>
7 : : #include <test/fuzz/fuzz.h>
8 : : #include <test/fuzz/util.h>
9 : :
10 : : #include <cstddef>
11 : : #include <cstdint>
12 : : #include <string>
13 : : #include <vector>
14 : :
15 [ + - ]: 484 : FUZZ_TARGET(span)
16 : : {
17 : 8 : FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
18 : :
19 : 8 : std::string str = fuzzed_data_provider.ConsumeBytesAsString(32);
20 [ - + ]: 8 : const std::span<const char> span{str};
21 : 8 : (void)span.data();
22 [ + - ]: 8 : (void)span.begin();
23 [ + - ]: 8 : (void)span.end();
24 [ + - ]: 8 : if (span.size() > 0) {
25 : 8 : const std::ptrdiff_t idx = fuzzed_data_provider.ConsumeIntegralInRange<std::ptrdiff_t>(0U, span.size() - 1U);
26 : 8 : (void)span.first(idx);
27 : 8 : (void)span.last(idx);
28 : 8 : (void)span.subspan(idx);
29 : 8 : (void)span.subspan(idx, span.size() - idx);
30 : 8 : (void)span[idx];
31 : : }
32 : 8 : }
|