Commit abbc07f12fdf1444c8aa0c161f3dfa8a494b7dff

Edward Thomson 2019-01-20T13:51:15

add with overflow: use SizeTAdd on Windows Windows provides <intsafe.h> which provides "performant" add and multiply with overflow operations. Use them when possible.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/src/integer.h b/src/integer.h
index 144a21b..12e71f7 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
 
 /**