aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2020-03-23 07:39:44 -0400
committerMarcoFalke <falke.marco@gmail.com>2020-03-23 07:39:47 -0400
commit97b0687501cee77a9170f9e288755a5d268e9bd4 (patch)
tree8671fac32c708d4d1453e6387740ab7e5b46e742
parentd478a737dbdd9c6e60718cdef3352dbe6c86aa10 (diff)
parent7c1ac70c01536a8dd5b455f5b268a087cecf10a1 (diff)
Merge #18393: tests: Don't assume presence of __builtin_mul_overflow(…) in MultiplicationOverflow(…) fuzzing harness
7c1ac70c01536a8dd5b455f5b268a087cecf10a1 tests: Don't assume presence of __builtin_mul_overflow in MultiplicationOverflow(...) fuzzing harness (practicalswift) Pull request description: Don't assume presence of `__builtin_mul_overflow(…)` in `MultiplicationOverflow(…)` fuzzing harness. Fixes #18389. ACKs for top commit: naumenkogs: ACK 7c1ac70 Tree-SHA512: b6f1040a088088ff7e4f5c038f0f710ca2b515387bac3cd249afe97613641f7f3754f61d73d7233f23b8296115fab5bbf656168624a2cb74909577440a49a359
-rw-r--r--src/test/fuzz/multiplication_overflow.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/test/fuzz/multiplication_overflow.cpp b/src/test/fuzz/multiplication_overflow.cpp
index 923db8058b..a4b158c18b 100644
--- a/src/test/fuzz/multiplication_overflow.cpp
+++ b/src/test/fuzz/multiplication_overflow.cpp
@@ -10,6 +10,14 @@
#include <string>
#include <vector>
+#if defined(__has_builtin)
+#if __has_builtin(__builtin_mul_overflow)
+#define HAVE_BUILTIN_MUL_OVERFLOW
+#endif
+#elif defined(__GNUC__) && (__GNUC__ >= 5)
+#define HAVE_BUILTIN_MUL_OVERFLOW
+#endif
+
namespace {
template <typename T>
void TestMultiplicationOverflow(FuzzedDataProvider& fuzzed_data_provider)
@@ -17,12 +25,18 @@ void TestMultiplicationOverflow(FuzzedDataProvider& fuzzed_data_provider)
const T i = fuzzed_data_provider.ConsumeIntegral<T>();
const T j = fuzzed_data_provider.ConsumeIntegral<T>();
const bool is_multiplication_overflow_custom = MultiplicationOverflow(i, j);
+#if defined(HAVE_BUILTIN_MUL_OVERFLOW)
T result_builtin;
const bool is_multiplication_overflow_builtin = __builtin_mul_overflow(i, j, &result_builtin);
assert(is_multiplication_overflow_custom == is_multiplication_overflow_builtin);
if (!is_multiplication_overflow_custom) {
assert(i * j == result_builtin);
}
+#else
+ if (!is_multiplication_overflow_custom) {
+ (void)(i * j);
+ }
+#endif
}
} // namespace
@@ -38,5 +52,4 @@ void test_one_input(const std::vector<uint8_t>& buffer)
TestMultiplicationOverflow<char>(fuzzed_data_provider);
TestMultiplicationOverflow<unsigned char>(fuzzed_data_provider);
TestMultiplicationOverflow<signed char>(fuzzed_data_provider);
- TestMultiplicationOverflow<bool>(fuzzed_data_provider);
}