mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-13 11:25:02 -05:00
tests: Don't assume presence of __builtin_mul_overflow in MultiplicationOverflow(...) fuzzing harness
This commit is contained in:
parent
5bf45fe2a9
commit
7c1ac70c01
1 changed files with 14 additions and 1 deletions
|
@ -10,6 +10,14 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#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 {
|
namespace {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void TestMultiplicationOverflow(FuzzedDataProvider& fuzzed_data_provider)
|
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 i = fuzzed_data_provider.ConsumeIntegral<T>();
|
||||||
const T j = fuzzed_data_provider.ConsumeIntegral<T>();
|
const T j = fuzzed_data_provider.ConsumeIntegral<T>();
|
||||||
const bool is_multiplication_overflow_custom = MultiplicationOverflow(i, j);
|
const bool is_multiplication_overflow_custom = MultiplicationOverflow(i, j);
|
||||||
|
#if defined(HAVE_BUILTIN_MUL_OVERFLOW)
|
||||||
T result_builtin;
|
T result_builtin;
|
||||||
const bool is_multiplication_overflow_builtin = __builtin_mul_overflow(i, j, &result_builtin);
|
const bool is_multiplication_overflow_builtin = __builtin_mul_overflow(i, j, &result_builtin);
|
||||||
assert(is_multiplication_overflow_custom == is_multiplication_overflow_builtin);
|
assert(is_multiplication_overflow_custom == is_multiplication_overflow_builtin);
|
||||||
if (!is_multiplication_overflow_custom) {
|
if (!is_multiplication_overflow_custom) {
|
||||||
assert(i * j == result_builtin);
|
assert(i * j == result_builtin);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if (!is_multiplication_overflow_custom) {
|
||||||
|
(void)(i * j);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -38,5 +52,4 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
||||||
TestMultiplicationOverflow<char>(fuzzed_data_provider);
|
TestMultiplicationOverflow<char>(fuzzed_data_provider);
|
||||||
TestMultiplicationOverflow<unsigned char>(fuzzed_data_provider);
|
TestMultiplicationOverflow<unsigned char>(fuzzed_data_provider);
|
||||||
TestMultiplicationOverflow<signed char>(fuzzed_data_provider);
|
TestMultiplicationOverflow<signed char>(fuzzed_data_provider);
|
||||||
TestMultiplicationOverflow<bool>(fuzzed_data_provider);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue