summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2019-01-20 13:51:15 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2019-01-20 13:51:15 +0000
commitabbc07f12fdf1444c8aa0c161f3dfa8a494b7dff (patch)
tree4301ec3c81318c7c2c4e7a92c28bddbf3159cec4
parentc6d47acfbfd514a12ac9fb14c87a247da7bfbf1d (diff)
downloadlibgit2-abbc07f12fdf1444c8aa0c161f3dfa8a494b7dff.tar.gz
add with overflow: use SizeTAdd on Windows
Windows provides <intsafe.h> which provides "performant" add and multiply with overflow operations. Use them when possible.
-rw-r--r--src/integer.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/integer.h b/src/integer.h
index 144a21bd8..12e71f76a 100644
--- a/src/integer.h
+++ b/src/integer.h
@@ -65,6 +65,16 @@ GIT_INLINE(int) git__is_int(long long p)
# error compiler has add with overflow intrinsics but SIZE_MAX is unknown
# endif
+/* Use Microsoft's safe integer handling functions where available */
+#elif defined(_MSC_VER)
+
+# include <intsafe.h>
+
+# define git__add_sizet_overflow(out, one, two) \
+ (SizeTAdd(one, two, out) != S_OK)
+# define git__multiply_sizet_overflow(out, one, two) \
+ (SizeTMult(one, two, out) != S_OK)
+
#else
/**