Merge bitcoin/bitcoin#30229: fuzz: Use std::span in FuzzBufferType

faa41e29d5 fuzz: Use std::span in FuzzBufferType (MarcoFalke)

Pull request description:

  The use of `Span` is problematic, because it lacks methods such as `rbegin`, leading to compile failures when used:

  ```
  error: no member named 'rbegin' in 'Span<const unsigned char>'
  ```

  One could fix `Span`, but it seems better to use `std::span`, given that `Span` will be removed anyway in the long term.

ACKs for top commit:
  dergoegge:
    utACK faa41e29d5

Tree-SHA512: 54bcaf51c83a1b48739cd7f1e8445c6eba0eb04231bce5c35591a47dddb3890ffcaf562cf932930443c80ab0e66950c4619560e6692240de0c52aeef3214facd
This commit is contained in:
merge-script
2024-06-12 18:16:07 +01:00
2 changed files with 5 additions and 6 deletions

View File

@@ -12,8 +12,8 @@
namespace { namespace {
/** Pop the first byte from a Span<const uint8_t>, and return it. */ /** Pop the first byte from a byte-span, and return it. */
uint8_t ReadByte(Span<const uint8_t>& buffer) uint8_t ReadByte(FuzzBufferType& buffer)
{ {
if (buffer.empty()) return 0; if (buffer.empty()) return 0;
uint8_t ret = buffer.front(); uint8_t ret = buffer.front();
@@ -23,7 +23,7 @@ uint8_t ReadByte(Span<const uint8_t>& buffer)
/** Perform a simulation fuzz test on BitSet type S. */ /** Perform a simulation fuzz test on BitSet type S. */
template<typename S> template<typename S>
void TestType(Span<const uint8_t> buffer) void TestType(FuzzBufferType buffer)
{ {
/** This fuzz test's design is based on the assumption that the actual bits stored in the /** This fuzz test's design is based on the assumption that the actual bits stored in the
* bitsets and their simulations do not matter for the purpose of detecting edge cases, thus * bitsets and their simulations do not matter for the purpose of detecting edge cases, thus

View File

@@ -5,10 +5,9 @@
#ifndef BITCOIN_TEST_FUZZ_FUZZ_H #ifndef BITCOIN_TEST_FUZZ_FUZZ_H
#define BITCOIN_TEST_FUZZ_FUZZ_H #define BITCOIN_TEST_FUZZ_FUZZ_H
#include <span.h>
#include <cstdint> #include <cstdint>
#include <functional> #include <functional>
#include <span>
#include <string_view> #include <string_view>
/** /**
@@ -23,7 +22,7 @@
#define LIMITED_WHILE(condition, limit) \ #define LIMITED_WHILE(condition, limit) \
for (unsigned _count{limit}; (condition) && _count; --_count) for (unsigned _count{limit}; (condition) && _count; --_count)
using FuzzBufferType = Span<const uint8_t>; using FuzzBufferType = std::span<const uint8_t>;
using TypeTestOneInput = std::function<void(FuzzBufferType)>; using TypeTestOneInput = std::function<void(FuzzBufferType)>;
struct FuzzTargetOptions { struct FuzzTargetOptions {