Skip to content

Commit abbc07f

Browse files
committed
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 parent c6d47ac commit abbc07f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/integer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ GIT_INLINE(int) git__is_int(long long p)
6565
# error compiler has add with overflow intrinsics but SIZE_MAX is unknown
6666
# endif
6767

68+
/* Use Microsoft's safe integer handling functions where available */
69+
#elif defined(_MSC_VER)
70+
71+
# include <intsafe.h>
72+
73+
# define git__add_sizet_overflow(out, one, two) \
74+
(SizeTAdd(one, two, out) != S_OK)
75+
# define git__multiply_sizet_overflow(out, one, two) \
76+
(SizeTMult(one, two, out) != S_OK)
77+
6878
#else
6979

7080
/**

0 commit comments

Comments
 (0)