From 14e3f2a1c916fccf375a6570e58072c4d007fc3c Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Thu, 31 Dec 2020 08:50:08 +0100 Subject: [PATCH] fuzz: Bump FuzzedDataProvider.h Latest version from https://raw.githubusercontent.com/llvm/llvm-project/70de7e0d9a95b7fcd7c105b06bd90fdf4e01f563/compiler-rt/include/fuzzer/FuzzedDataProvider.h Github-Pull: #20812 Rebased-From: fafce49336e18033b26948886bbd7342c779b246 --- src/test/fuzz/FuzzedDataProvider.h | 9 +++++++++ 1 file changed, 9 insertions(+) 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 +#include #include #include #include @@ -71,6 +72,8 @@ class FuzzedDataProvider { // Returns a value from the given array. template T PickValueInArray(const T (&array)[size]); + template + T PickValueInArray(const std::array &array); template T PickValueInArray(std::initializer_list 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(0, size - 1)]; } +template +T FuzzedDataProvider::PickValueInArray(const std::array &array) { + static_assert(size > 0, "The array must be non empty."); + return array[ConsumeIntegralInRange(0, size - 1)]; +} + template T FuzzedDataProvider::PickValueInArray(std::initializer_list list) { // TODO(Dor1s): switch to static_assert once C++14 is allowed.