merge bitcoin#20812: Bump FuzzedDataProvider.h

This commit is contained in:
Kittywhiskers Van Gogh 2020-12-31 08:50:08 +01:00 committed by PastaPastaPasta
parent f6b2a1722a
commit ba90fb6338

View File

@ -14,6 +14,7 @@
#define LLVM_FUZZER_FUZZED_DATA_PROVIDER_H_
#include <algorithm>
#include <array>
#include <climits>
#include <cstddef>
#include <cstdint>
@ -72,6 +73,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.
@ -302,6 +305,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.