Merge #20812: fuzz: Bump FuzzedDataProvider.h

fa5b935840 fuzz: Remove duplicate ALL_OUTPUT_TYPE array (MarcoFalke)
fafce49336 fuzz: Bump FuzzedDataProvider.h (MarcoFalke)

Pull request description:

ACKs for top commit:
  practicalswift:
    ACK fa5b935840

Tree-SHA512: eacf97f26869fb226d7ac5ea1f8204b25ebb7551d084af0da02cc1a850a1fdf7d7a4919386b7f27ab9acb1873f63aafe9ad9f8ea2668aea366e11c7c0991a2f4
This commit is contained in:
MarcoFalke 2020-12-31 13:59:54 +01:00
commit 409afd7153
No known key found for this signature in database
GPG key ID: D2EA4850E7528B25
2 changed files with 10 additions and 7 deletions

View file

@ -14,6 +14,7 @@
#define LLVM_FUZZER_FUZZED_DATA_PROVIDER_H_
#include <algorithm>
#include <array>
#include <climits>
#include <cstddef>
#include <cstdint>
@ -71,6 +72,8 @@ class FuzzedDataProvider {
// Returns a value from the given array.
template <typename T, size_t size> T PickValueInArray(const T (&array)[size]);
template <typename T, size_t size>
T PickValueInArray(const std::array<T, size> &array);
template <typename T> T PickValueInArray(std::initializer_list<const T> list);
// Writes data to the given destination and returns number of bytes written.
@ -301,6 +304,12 @@ T FuzzedDataProvider::PickValueInArray(const T (&array)[size]) {
return array[ConsumeIntegralInRange<size_t>(0, size - 1)];
}
template <typename T, size_t size>
T FuzzedDataProvider::PickValueInArray(const std::array<T, size> &array) {
static_assert(size > 0, "The array must be non empty.");
return array[ConsumeIntegralInRange<size_t>(0, size - 1)];
}
template <typename T>
T FuzzedDataProvider::PickValueInArray(std::initializer_list<const T> list) {
// TODO(Dor1s): switch to static_assert once C++14 is allowed.

View file

@ -34,12 +34,6 @@ constexpr FeeEstimateHorizon ALL_FEE_EST_HORIZON[] = {
FeeEstimateHorizon::MED_HALFLIFE,
FeeEstimateHorizon::LONG_HALFLIFE,
};
constexpr OutputType ALL_OUTPUT_TYPE[] = {
OutputType::LEGACY,
OutputType::P2SH_SEGWIT,
OutputType::BECH32,
};
}; // namespace
// The fuzzing kitchen sink: Fuzzing harness for functions that need to be
@ -56,7 +50,7 @@ FUZZ_TARGET(kitchen_sink)
(void)StringForFeeEstimateHorizon(fuzzed_data_provider.PickValueInArray(ALL_FEE_EST_HORIZON));
const OutputType output_type = fuzzed_data_provider.PickValueInArray(ALL_OUTPUT_TYPE);
const OutputType output_type = fuzzed_data_provider.PickValueInArray(OUTPUT_TYPES);
const std::string& output_type_string = FormatOutputType(output_type);
OutputType output_type_parsed;
const bool parsed = ParseOutputType(output_type_string, output_type_parsed);