vendor/libgit2/src/integer.h in rugged-1.1.0 vs vendor/libgit2/src/integer.h in rugged-1.1.1
- old
+ new
@@ -75,10 +75,13 @@
# define git__add_int_overflow(out, one, two) \
__builtin_sadd_overflow(one, two, out)
# define git__sub_int_overflow(out, one, two) \
__builtin_ssub_overflow(one, two, out)
+# define git__add_int64_overflow(out, one, two) \
+ __builtin_add_overflow(one, two, out)
+
/* Use Microsoft's safe integer handling functions where available */
#elif defined(_MSC_VER)
# define ENABLE_INTSAFE_SIGNED_FUNCTIONS
# include <intsafe.h>
@@ -90,10 +93,13 @@
#define git__add_int_overflow(out, one, two) \
(IntAdd(one, two, out) != S_OK)
#define git__sub_int_overflow(out, one, two) \
(IntSub(one, two, out) != S_OK)
+#define git__add_int64_overflow(out, one, two) \
+ (LongLongAdd(one, two, out) != S_OK)
+
#else
/**
* Sets `one + two` into `out`, unless the arithmetic would overflow.
* @return false if the result fits in a `size_t`, true on overflow.
@@ -131,9 +137,18 @@
{
if ((two > 0 && one < (INT_MIN + two)) ||
(two < 0 && one > (INT_MAX + two)))
return true;
*out = one - two;
+ return false;
+}
+
+GIT_INLINE(bool) git__add_int64_overflow(int64_t *out, int64_t one, int64_t two)
+{
+ if ((two > 0 && one > (INT64_MAX - two)) ||
+ (two < 0 && one < (INT64_MIN - two)))
+ return true;
+ *out = one + two;
return false;
}
#endif