Skip to content

Commit 409afd7

Browse files
author
MarcoFalke
committed
Merge #20812: fuzz: Bump FuzzedDataProvider.h
fa5b935 fuzz: Remove duplicate ALL_OUTPUT_TYPE array (MarcoFalke) fafce49 fuzz: Bump FuzzedDataProvider.h (MarcoFalke) Pull request description: ACKs for top commit: practicalswift: ACK fa5b935 Tree-SHA512: eacf97f26869fb226d7ac5ea1f8204b25ebb7551d084af0da02cc1a850a1fdf7d7a4919386b7f27ab9acb1873f63aafe9ad9f8ea2668aea366e11c7c0991a2f4
2 parents f1f26b8 + fa5b935 commit 409afd7

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/test/fuzz/FuzzedDataProvider.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LLVM_FUZZER_FUZZED_DATA_PROVIDER_H_
1515

1616
#include <algorithm>
17+
#include <array>
1718
#include <climits>
1819
#include <cstddef>
1920
#include <cstdint>
@@ -71,6 +72,8 @@ class FuzzedDataProvider {
7172

7273
// Returns a value from the given array.
7374
template <typename T, size_t size> T PickValueInArray(const T (&array)[size]);
75+
template <typename T, size_t size>
76+
T PickValueInArray(const std::array<T, size> &array);
7477
template <typename T> T PickValueInArray(std::initializer_list<const T> list);
7578

7679
// Writes data to the given destination and returns number of bytes written.
@@ -301,6 +304,12 @@ T FuzzedDataProvider::PickValueInArray(const T (&array)[size]) {
301304
return array[ConsumeIntegralInRange<size_t>(0, size - 1)];
302305
}
303306

307+
template <typename T, size_t size>
308+
T FuzzedDataProvider::PickValueInArray(const std::array<T, size> &array) {
309+
static_assert(size > 0, "The array must be non empty.");
310+
return array[ConsumeIntegralInRange<size_t>(0, size - 1)];
311+
}
312+
304313
template <typename T>
305314
T FuzzedDataProvider::PickValueInArray(std::initializer_list<const T> list) {
306315
// TODO(Dor1s): switch to static_assert once C++14 is allowed.

src/test/fuzz/kitchen_sink.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ constexpr FeeEstimateHorizon ALL_FEE_EST_HORIZON[] = {
3434
FeeEstimateHorizon::MED_HALFLIFE,
3535
FeeEstimateHorizon::LONG_HALFLIFE,
3636
};
37-
38-
constexpr OutputType ALL_OUTPUT_TYPE[] = {
39-
OutputType::LEGACY,
40-
OutputType::P2SH_SEGWIT,
41-
OutputType::BECH32,
42-
};
4337
}; // namespace
4438

4539
// The fuzzing kitchen sink: Fuzzing harness for functions that need to be
@@ -56,7 +50,7 @@ FUZZ_TARGET(kitchen_sink)
5650

5751
(void)StringForFeeEstimateHorizon(fuzzed_data_provider.PickValueInArray(ALL_FEE_EST_HORIZON));
5852

59-
const OutputType output_type = fuzzed_data_provider.PickValueInArray(ALL_OUTPUT_TYPE);
53+
const OutputType output_type = fuzzed_data_provider.PickValueInArray(OUTPUT_TYPES);
6054
const std::string& output_type_string = FormatOutputType(output_type);
6155
OutputType output_type_parsed;
6256
const bool parsed = ParseOutputType(output_type_string, output_type_parsed);

0 commit comments

Comments
 (0)