Skip to content

Commit 97b0687

Browse files
author
MarcoFalke
committed
Merge #18393: tests: Don't assume presence of __builtin_mul_overflow(…) in MultiplicationOverflow(…) fuzzing harness
7c1ac70 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
2 parents d478a73 + 7c1ac70 commit 97b0687

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/test/fuzz/multiplication_overflow.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,33 @@
1010
#include <string>
1111
#include <vector>
1212

13+
#if defined(__has_builtin)
14+
#if __has_builtin(__builtin_mul_overflow)
15+
#define HAVE_BUILTIN_MUL_OVERFLOW
16+
#endif
17+
#elif defined(__GNUC__) && (__GNUC__ >= 5)
18+
#define HAVE_BUILTIN_MUL_OVERFLOW
19+
#endif
20+
1321
namespace {
1422
template <typename T>
1523
void TestMultiplicationOverflow(FuzzedDataProvider& fuzzed_data_provider)
1624
{
1725
const T i = fuzzed_data_provider.ConsumeIntegral<T>();
1826
const T j = fuzzed_data_provider.ConsumeIntegral<T>();
1927
const bool is_multiplication_overflow_custom = MultiplicationOverflow(i, j);
28+
#if defined(HAVE_BUILTIN_MUL_OVERFLOW)
2029
T result_builtin;
2130
const bool is_multiplication_overflow_builtin = __builtin_mul_overflow(i, j, &result_builtin);
2231
assert(is_multiplication_overflow_custom == is_multiplication_overflow_builtin);
2332
if (!is_multiplication_overflow_custom) {
2433
assert(i * j == result_builtin);
2534
}
35+
#else
36+
if (!is_multiplication_overflow_custom) {
37+
(void)(i * j);
38+
}
39+
#endif
2640
}
2741
} // namespace
2842

@@ -38,5 +52,4 @@ void test_one_input(const std::vector<uint8_t>& buffer)
3852
TestMultiplicationOverflow<char>(fuzzed_data_provider);
3953
TestMultiplicationOverflow<unsigned char>(fuzzed_data_provider);
4054
TestMultiplicationOverflow<signed char>(fuzzed_data_provider);
41-
TestMultiplicationOverflow<bool>(fuzzed_data_provider);
4255
}

0 commit comments

Comments
 (0)