diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:47:08 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:47:08 +0000 |
commit | 29b5ab554790bb57337a3b6ab9dcd963cf69d22e (patch) | |
tree | be1456d2bc6c1fb078695fad7bc8f6b212062d3c /tests/util/integer.c | |
parent | Initial commit. (diff) | |
download | libgit2-29b5ab554790bb57337a3b6ab9dcd963cf69d22e.tar.xz libgit2-29b5ab554790bb57337a3b6ab9dcd963cf69d22e.zip |
Adding upstream version 1.7.2+ds.upstream/1.7.2+ds
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | tests/util/integer.c | 253 |
1 files changed, 253 insertions, 0 deletions
diff --git a/tests/util/integer.c b/tests/util/integer.c new file mode 100644 index 0000000..2226ab4 --- /dev/null +++ b/tests/util/integer.c @@ -0,0 +1,253 @@ +#include "clar_libgit2.h" + +void test_integer__multiply_int64_no_overflow(void) +{ +#if !defined(git__multiply_int64_overflow) + int64_t result = 0; + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x0), INT64_C(0x0))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x0), INT64_C(0x1))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x0), INT64_C(-0x1))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x0), INT64_C(0x2))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x0), INT64_C(-0x2))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x0), INT64_C(0x7ffffffffffffff))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x0), INT64_C(-0x7ffffffffffffff))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x0), INT64_C(0x800000000000000))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x0), INT64_C(-0x800000000000000))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x0), INT64_C(0x7fffffffffffffff))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x0), INT64_C(-0x7fffffffffffffff))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x0), INT64_C(-0x8000000000000000))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x1), INT64_C(0x0))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x1), INT64_C(0x1))); + cl_assert_equal_i(result, INT64_C(0x1)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x1), INT64_C(-0x1))); + cl_assert_equal_i(result, INT64_C(-0x1)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x1), INT64_C(0x2))); + cl_assert_equal_i(result, INT64_C(0x2)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x1), INT64_C(-0x2))); + cl_assert_equal_i(result, INT64_C(-0x2)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x1), INT64_C(0x7ffffffffffffff))); + cl_assert_equal_i(result, INT64_C(0x7ffffffffffffff)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x1), INT64_C(-0x7ffffffffffffff))); + cl_assert_equal_i(result, INT64_C(-0x7ffffffffffffff)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x1), INT64_C(0x800000000000000))); + cl_assert_equal_i(result, INT64_C(0x800000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x1), INT64_C(-0x800000000000000))); + cl_assert_equal_i(result, INT64_C(-0x800000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x1), INT64_C(0x7fffffffffffffff))); + cl_assert_equal_i(result, INT64_C(0x7fffffffffffffff)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x1), INT64_C(-0x7fffffffffffffff))); + cl_assert_equal_i(result, INT64_C(-0x7fffffffffffffff)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x1), INT64_C(0x0))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x1), INT64_C(0x1))); + cl_assert_equal_i(result, INT64_C(-0x1)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x1), INT64_C(-0x1))); + cl_assert_equal_i(result, INT64_C(0x1)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x1), INT64_C(0x2))); + cl_assert_equal_i(result, INT64_C(-0x2)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x1), INT64_C(-0x2))); + cl_assert_equal_i(result, INT64_C(0x2)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x1), INT64_C(0x7ffffffffffffff))); + cl_assert_equal_i(result, INT64_C(-0x7ffffffffffffff)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x1), INT64_C(-0x7ffffffffffffff))); + cl_assert_equal_i(result, INT64_C(0x7ffffffffffffff)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x1), INT64_C(0x800000000000000))); + cl_assert_equal_i(result, INT64_C(-0x800000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x1), INT64_C(-0x800000000000000))); + cl_assert_equal_i(result, INT64_C(0x800000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x1), INT64_C(0x7fffffffffffffff))); + cl_assert_equal_i(result, INT64_C(-0x7fffffffffffffff)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x1), INT64_C(-0x7fffffffffffffff))); + cl_assert_equal_i(result, INT64_C(0x7fffffffffffffff)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x2), INT64_C(0x0))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x2), INT64_C(0x1))); + cl_assert_equal_i(result, INT64_C(0x2)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x2), INT64_C(-0x1))); + cl_assert_equal_i(result, INT64_C(-0x2)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x2), INT64_C(0x2))); + cl_assert_equal_i(result, INT64_C(0x4)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x2), INT64_C(-0x2))); + cl_assert_equal_i(result, INT64_C(-0x4)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x2), INT64_C(0x7ffffffffffffff))); + cl_assert_equal_i(result, INT64_C(0xffffffffffffffe)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x2), INT64_C(-0x7ffffffffffffff))); + cl_assert_equal_i(result, INT64_C(-0xffffffffffffffe)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x2), INT64_C(0x800000000000000))); + cl_assert_equal_i(result, INT64_C(0x1000000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x2), INT64_C(-0x800000000000000))); + cl_assert_equal_i(result, INT64_C(-0x1000000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x2), INT64_C(0x0))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x2), INT64_C(0x1))); + cl_assert_equal_i(result, INT64_C(-0x2)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x2), INT64_C(-0x1))); + cl_assert_equal_i(result, INT64_C(0x2)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x2), INT64_C(0x2))); + cl_assert_equal_i(result, INT64_C(-0x4)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x2), INT64_C(-0x2))); + cl_assert_equal_i(result, INT64_C(0x4)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x2), INT64_C(0x7ffffffffffffff))); + cl_assert_equal_i(result, INT64_C(-0xffffffffffffffe)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x2), INT64_C(-0x7ffffffffffffff))); + cl_assert_equal_i(result, INT64_C(0xffffffffffffffe)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x2), INT64_C(0x800000000000000))); + cl_assert_equal_i(result, INT64_C(-0x1000000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x2), INT64_C(-0x800000000000000))); + cl_assert_equal_i(result, INT64_C(0x1000000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x2), INT64_C(-0x4000000000000000))); + cl_assert_equal_i(result, INT64_C(-0x8000000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x7ffffffffffffff), INT64_C(0x0))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x7ffffffffffffff), INT64_C(0x1))); + cl_assert_equal_i(result, INT64_C(0x7ffffffffffffff)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x7ffffffffffffff), INT64_C(-0x1))); + cl_assert_equal_i(result, INT64_C(-0x7ffffffffffffff)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x7ffffffffffffff), INT64_C(0x2))); + cl_assert_equal_i(result, INT64_C(0xffffffffffffffe)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x7ffffffffffffff), INT64_C(-0x2))); + cl_assert_equal_i(result, INT64_C(-0xffffffffffffffe)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x7ffffffffffffff), INT64_C(0x0))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x7ffffffffffffff), INT64_C(0x1))); + cl_assert_equal_i(result, INT64_C(-0x7ffffffffffffff)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x7ffffffffffffff), INT64_C(-0x1))); + cl_assert_equal_i(result, INT64_C(0x7ffffffffffffff)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x7ffffffffffffff), INT64_C(0x2))); + cl_assert_equal_i(result, INT64_C(-0xffffffffffffffe)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x7ffffffffffffff), INT64_C(-0x2))); + cl_assert_equal_i(result, INT64_C(0xffffffffffffffe)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x800000000000000), INT64_C(0x0))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x800000000000000), INT64_C(0x1))); + cl_assert_equal_i(result, INT64_C(0x800000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x800000000000000), INT64_C(-0x1))); + cl_assert_equal_i(result, INT64_C(-0x800000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x800000000000000), INT64_C(0x2))); + cl_assert_equal_i(result, INT64_C(0x1000000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x800000000000000), INT64_C(-0x2))); + cl_assert_equal_i(result, INT64_C(-0x1000000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x800000000000000), INT64_C(0x0))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x800000000000000), INT64_C(0x1))); + cl_assert_equal_i(result, INT64_C(-0x800000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x800000000000000), INT64_C(-0x1))); + cl_assert_equal_i(result, INT64_C(0x800000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x800000000000000), INT64_C(0x2))); + cl_assert_equal_i(result, INT64_C(-0x1000000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x800000000000000), INT64_C(-0x2))); + cl_assert_equal_i(result, INT64_C(0x1000000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x7fffffffffffffff), INT64_C(0x0))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x7fffffffffffffff), INT64_C(0x1))); + cl_assert_equal_i(result, INT64_C(0x7fffffffffffffff)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(0x7fffffffffffffff), INT64_C(-0x1))); + cl_assert_equal_i(result, INT64_C(-0x7fffffffffffffff)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x4000000000000000), INT64_C(0x2))); + cl_assert_equal_i(result, INT64_C(-0x8000000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x7fffffffffffffff), INT64_C(0x0))); + cl_assert_equal_i(result, INT64_C(0x0)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x7fffffffffffffff), INT64_C(0x1))); + cl_assert_equal_i(result, INT64_C(-0x7fffffffffffffff)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x7fffffffffffffff), INT64_C(-0x1))); + cl_assert_equal_i(result, INT64_C(0x7fffffffffffffff)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x8000000000000000), INT64_C(0x0))); + cl_assert_equal_i(result, INT64_C(0x0)); +#endif +} + +void test_integer__multiply_int64_overflow(void) +{ +#if !defined(git__multiply_int64_overflow) + int64_t result = 0; + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x2), INT64_C(0x4000000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x2), INT64_C(0x7fffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x2), INT64_C(-0x7fffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x2), INT64_C(-0x8000000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x2), INT64_C(0x7fffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x2), INT64_C(-0x7fffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x2), INT64_C(-0x8000000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x7ffffffffffffff), INT64_C(0x7ffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x7ffffffffffffff), INT64_C(-0x7ffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x7ffffffffffffff), INT64_C(0x800000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x7ffffffffffffff), INT64_C(-0x800000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x7ffffffffffffff), INT64_C(0x7fffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x7ffffffffffffff), INT64_C(-0x7fffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x7ffffffffffffff), INT64_C(-0x8000000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x7ffffffffffffff), INT64_C(0x7ffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x7ffffffffffffff), INT64_C(-0x7ffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x7ffffffffffffff), INT64_C(0x800000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x7ffffffffffffff), INT64_C(-0x800000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x7ffffffffffffff), INT64_C(0x7fffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x7ffffffffffffff), INT64_C(-0x7fffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x7ffffffffffffff), INT64_C(-0x8000000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x800000000000000), INT64_C(0x7ffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x800000000000000), INT64_C(-0x7ffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x800000000000000), INT64_C(0x800000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x800000000000000), INT64_C(-0x800000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x800000000000000), INT64_C(0x7fffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x800000000000000), INT64_C(-0x7fffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x800000000000000), INT64_C(-0x8000000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x800000000000000), INT64_C(0x7ffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x800000000000000), INT64_C(-0x7ffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x800000000000000), INT64_C(0x800000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x800000000000000), INT64_C(-0x800000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x800000000000000), INT64_C(0x7fffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x800000000000000), INT64_C(-0x7fffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x800000000000000), INT64_C(-0x8000000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x4000000000000000), INT64_C(0x2))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x7fffffffffffffff), INT64_C(0x2))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x7fffffffffffffff), INT64_C(-0x2))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x7fffffffffffffff), INT64_C(0x7ffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x7fffffffffffffff), INT64_C(-0x7ffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x7fffffffffffffff), INT64_C(0x800000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x7fffffffffffffff), INT64_C(-0x800000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x7fffffffffffffff), INT64_C(0x7fffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x7fffffffffffffff), INT64_C(-0x7fffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x7fffffffffffffff), INT64_C(-0x8000000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x7fffffffffffffff), INT64_C(0x2))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x7fffffffffffffff), INT64_C(-0x2))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x7fffffffffffffff), INT64_C(0x7ffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x7fffffffffffffff), INT64_C(-0x7ffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x7fffffffffffffff), INT64_C(0x800000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x7fffffffffffffff), INT64_C(-0x800000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x7fffffffffffffff), INT64_C(0x7fffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x7fffffffffffffff), INT64_C(-0x7fffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x7fffffffffffffff), INT64_C(-0x8000000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x8000000000000000), INT64_C(0x2))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x8000000000000000), INT64_C(-0x2))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x8000000000000000), INT64_C(0x7ffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x8000000000000000), INT64_C(-0x7ffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x8000000000000000), INT64_C(0x800000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x8000000000000000), INT64_C(-0x800000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x8000000000000000), INT64_C(0x7fffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x8000000000000000), INT64_C(-0x7fffffffffffffff))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x8000000000000000), INT64_C(-0x8000000000000000))); +#endif +} + +void test_integer__multiply_int64_edge_cases(void) +{ +#if !defined(git__multiply_int64_overflow) + int64_t result = 0; + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x8000000000000000), INT64_C(-0x1))); + cl_assert_equal_i(result, INT64_C(-0x8000000000000000)); + cl_assert(!git__multiply_int64_overflow(&result, INT64_C(-0x1), INT64_C(-0x8000000000000000))); + cl_assert_equal_i(result, INT64_C(-0x8000000000000000)); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(0x1), INT64_C(-0x8000000000000000))); + cl_assert(git__multiply_int64_overflow(&result, INT64_C(-0x8000000000000000), INT64_C(0x1))); +#endif +} |