File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 10
10
#include < string>
11
11
#include < vector>
12
12
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
+
13
21
namespace {
14
22
template <typename T>
15
23
void TestMultiplicationOverflow (FuzzedDataProvider& fuzzed_data_provider)
16
24
{
17
25
const T i = fuzzed_data_provider.ConsumeIntegral <T>();
18
26
const T j = fuzzed_data_provider.ConsumeIntegral <T>();
19
27
const bool is_multiplication_overflow_custom = MultiplicationOverflow (i, j);
28
+ #if defined(HAVE_BUILTIN_MUL_OVERFLOW)
20
29
T result_builtin;
21
30
const bool is_multiplication_overflow_builtin = __builtin_mul_overflow (i, j, &result_builtin);
22
31
assert (is_multiplication_overflow_custom == is_multiplication_overflow_builtin);
23
32
if (!is_multiplication_overflow_custom) {
24
33
assert (i * j == result_builtin);
25
34
}
35
+ #else
36
+ if (!is_multiplication_overflow_custom) {
37
+ (void )(i * j);
38
+ }
39
+ #endif
26
40
}
27
41
} // namespace
28
42
@@ -38,5 +52,4 @@ void test_one_input(const std::vector<uint8_t>& buffer)
38
52
TestMultiplicationOverflow<char >(fuzzed_data_provider);
39
53
TestMultiplicationOverflow<unsigned char >(fuzzed_data_provider);
40
54
TestMultiplicationOverflow<signed char >(fuzzed_data_provider);
41
- TestMultiplicationOverflow<bool >(fuzzed_data_provider);
42
55
}
You can’t perform that action at this time.
0 commit comments