diff options
author | practicalswift <practicalswift@users.noreply.github.com> | 2020-04-07 16:31:43 +0000 |
---|---|---|
committer | practicalswift <practicalswift@users.noreply.github.com> | 2020-04-08 14:45:27 +0000 |
commit | 7b9a2dc86426926038b2f49d3d4ce4cb64dcd14b (patch) | |
tree | 64078fd73e0a6d17ba84e15ac83f08302944387e /src/test/fuzz/util.h | |
parent | 44fb2a596b4a1aa70253c4145c35be6de68da22a (diff) | |
download | bitcoin-7b9a2dc86426926038b2f49d3d4ce4cb64dcd14b.tar.xz |
tests: Add fuzzing harness for AdditionOverflow(...)
Diffstat (limited to 'src/test/fuzz/util.h')
-rw-r--r-- | src/test/fuzz/util.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/test/fuzz/util.h b/src/test/fuzz/util.h index b70ea6d90e..ba4b012f95 100644 --- a/src/test/fuzz/util.h +++ b/src/test/fuzz/util.h @@ -120,4 +120,15 @@ NODISCARD bool MultiplicationOverflow(const T i, const T j) noexcept } } +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 |