summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlhchavez <lhchavez@lhchavez.com>2020-12-18 19:43:13 -0800
committerlhchavez <lhchavez@lhchavez.com>2020-12-18 19:44:26 -0800
commite9b98cd53089077cb3c547b6f3870c51e3b128cc (patch)
tree740684ab0147590869652acc4c7ff2352bb80cd8
parentc76e9f22912e3b987a4e4590eb386477ae114f85 (diff)
downloadlibgit2-e9b98cd53089077cb3c547b6f3870c51e3b128cc.tar.gz
Third attempt to fix the 32-bit version of `git__multiply_int64_overflow`
This change should now fix the issue for realsies. `./libgit2_clar -score::strtol` passes on a 32-bit Docker.
-rw-r--r--src/integer.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/integer.h b/src/integer.h
index 28122a99f..724e076a0 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;
}