diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/fuzz/FuzzedDataProvider.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/test/fuzz/FuzzedDataProvider.h b/src/test/fuzz/FuzzedDataProvider.h index 83bcd0134a..744a9d78ce 100644 --- a/src/test/fuzz/FuzzedDataProvider.h +++ b/src/test/fuzz/FuzzedDataProvider.h @@ -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. |