Skip to content

Commit a67e5e0

Browse files
authored
Merge pull request libgit2#5743 from lhchavez/fix-clang-32-bit-tests
Third attempt to fix the 32-bit version of `git__multiply_int64_overf…
2 parents c76e9f2 + e9b98cd commit a67e5e0

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/integer.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,18 @@ GIT_INLINE(bool) git__add_int64_overflow(int64_t *out, int64_t one, int64_t two)
166166
#if !defined(git__multiply_int64_overflow)
167167
GIT_INLINE(bool) git__multiply_int64_overflow(int64_t *out, int64_t one, int64_t two)
168168
{
169-
if ((one == -1 && two == INT_MIN) ||
170-
(two == -1 && one == INT_MIN) ||
171-
(one && INT64_MAX / one < two) ||
172-
(one && INT64_MIN / one > two))
169+
if ((one == -1 && two == INT64_MIN) ||
170+
(two == -1 && one == INT64_MIN))
173171
return true;
172+
if (one && two) {
173+
if (one > 0 == two > 0) {
174+
if (INT64_MAX / one < two)
175+
return true;
176+
} else {
177+
if (INT64_MIN / one < two)
178+
return true;
179+
}
180+
}
174181
*out = one * two;
175182
return false;
176183
}

0 commit comments

Comments
 (0)