Changeset View
Changeset View
Standalone View
Standalone View
src/test/fuzz/util.h
Show First 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | if (std::numeric_limits<T>::is_signed) { | ||||
return i != 0 && (j < (std::numeric_limits<T>::max() / i)); | return i != 0 && (j < (std::numeric_limits<T>::max() / i)); | ||||
} | } | ||||
} | } | ||||
} else { | } else { | ||||
return j != 0 && i > std::numeric_limits<T>::max() / j; | return j != 0 && i > std::numeric_limits<T>::max() / j; | ||||
} | } | ||||
} | } | ||||
template <class T> | |||||
NODISCARD bool AdditionOverflow(const T i, const T j) noexcept { | |||||
static_assert(std::is_integral<T>::value, "Integral required."); | |||||
if (std::numeric_limits<T>::is_signed) { | |||||
return (i > 0 && j > std::numeric_limits<T>::max() - i) || | |||||
(i < 0 && j < std::numeric_limits<T>::min() - i); | |||||
} | |||||
return std::numeric_limits<T>::max() - i < j; | |||||
} | |||||
#endif // BITCOIN_TEST_FUZZ_UTIL_H | #endif // BITCOIN_TEST_FUZZ_UTIL_H |