MarcoFalke 4 years ago
parent a48c9d3161
commit 14e3f2a1c9

@ -14,6 +14,7 @@
#define LLVM_FUZZER_FUZZED_DATA_PROVIDER_H_ #define LLVM_FUZZER_FUZZED_DATA_PROVIDER_H_
#include <algorithm> #include <algorithm>
#include <array>
#include <climits> #include <climits>
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
@ -71,6 +72,8 @@ class FuzzedDataProvider {
// Returns a value from the given array. // 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 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); template <typename T> T PickValueInArray(std::initializer_list<const T> list);
// Writes data to the given destination and returns number of bytes written. // 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)]; 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> template <typename T>
T FuzzedDataProvider::PickValueInArray(std::initializer_list<const T> list) { T FuzzedDataProvider::PickValueInArray(std::initializer_list<const T> list) {
// TODO(Dor1s): switch to static_assert once C++14 is allowed. // TODO(Dor1s): switch to static_assert once C++14 is allowed.

Loading…
Cancel
Save