aboutsummaryrefslogtreecommitdiff
path: root/git-compat-util.h
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-01-22 18:52:13 +0100
committerJunio C Hamano <gitster@pobox.com>2017-01-23 11:02:36 -0800
commit3ca869940994866796edf9e53e52d80f82c3c04c (patch)
treef142a9dd9059877bc251038bed73f131f89f4733 /git-compat-util.h
parent04ee8b875b96c096c479132adca02fa734c3fa96 (diff)
downloadgit-3ca869940994866796edf9e53e52d80f82c3c04c.tar.gz
git-3ca869940994866796edf9e53e52d80f82c3c04c.tar.xz
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>
Diffstat (limited to 'git-compat-util.h')
-rw-r--r--git-compat-util.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index f706744e6..f46d40e4a 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -994,6 +994,11 @@ int git_qsort_s(void *base, size_t nmemb, size_t size,
#define qsort_s git_qsort_s
#endif
+#define QSORT_S(base, n, compar, ctx) do { \
+ if (qsort_s((base), (n), sizeof(*(base)), compar, ctx)) \
+ die("BUG: qsort_s() failed"); \
+} while (0)
+
#ifndef REG_STARTEND
#error "Git requires REG_STARTEND support. Compile with NO_REGEX=NeedsStartEnd"
#endif