Commit a67e5e0883c79e86e4895201292296f61b719b6c

Edward Thomson 2020-12-19T09:57:11

Merge pull request #5743 from lhchavez/fix-clang-32-bit-tests Third attempt to fix the 32-bit version of `git__multiply_int64_overf…

diff --git a/src/integer.h b/src/integer.h
index 28122a9..724e076 100644
--- a/src/integer.h
+++ b/src/integer.h
@@ -166,11 +166,18 @@ GIT_INLINE(bool) git__add_int64_overflow(int64_t *out, int64_t one, int64_t two)
 #if !defined(git__multiply_int64_overflow)
 GIT_INLINE(bool) git__multiply_int64_overflow(int64_t *out, int64_t one, int64_t two)
 {
-	if ((one == -1 && two == INT_MIN) ||
-	    (two == -1 && one == INT_MIN) ||
-	    (one && INT64_MAX / one < two) ||
-	    (one && INT64_MIN / one > two))
+	if ((one == -1 && two == INT64_MIN) ||
+	    (two == -1 && one == INT64_MIN))
 		return true;
+	if (one && two) {
+		if (one > 0 == two > 0) {
+			if (INT64_MAX / one < two)
+				return true;
+		} else {
+			if (INT64_MIN / one < two)
+				return true;
+		}
+	}
 	*out = one * two;
 	return false;
 }