add QSORT_S
Add the macro QSORT_S, a convenient wrapper for qsort_s() that infers the size of the array elements and dies on error. Basically all possible errors are programming mistakes (passing NULL as base of a non-empty array, passing NULL as comparison function, out-of-bounds accesses), so terminating the program should be acceptable for most callers. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jan 22, 2017 at 18:52 UTC
3ca869940994866796edf9e53e52d80f82c3c04c
1 file changed
+5
git-compat-util.h
+5
@@ -994,6 +994,11 @@ int git_qsort_s(void *base, size_t nmemb, size_t size,
994
#define qsort_s git_qsort_s
995
#endif
996
997
+#define QSORT_S(base, n, compar, ctx) do { \
998
+ if (qsort_s((base), (n), sizeof(*(base)), compar, ctx)) \
999
+ die("BUG: qsort_s() failed"); \
1000
+} while (0)
1001
+
1002
#ifndef REG_STARTEND
1003
#error "Git requires REG_STARTEND support. Compile with NO_REGEX=NeedsStartEnd"
1004
#endif