Commit 8b884b9a by Edward Thomson

util: include git__add_int64_overflow

Cherry-pick `git__add_int64_overflow` functionality introduced in
e99e833f.
parent ebe771b3
......@@ -77,6 +77,9 @@ GIT_INLINE(int) git__is_int(long long p)
# 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)
......@@ -92,6 +95,9 @@ GIT_INLINE(int) git__is_int(long long p)
#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
/**
......@@ -136,6 +142,15 @@ GIT_INLINE(bool) git__sub_int_overflow(int *out, int one, int 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
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment