Skip to content

Commit 3ca8699

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 04ee8b8 commit 3ca8699

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

git-compat-util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,11 @@ int git_qsort_s(void *base, size_t nmemb, size_t size,
994994
#define qsort_s git_qsort_s
995995
#endif
996996

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+
9971002
#ifndef REG_STARTEND
9981003
#error "Git requires REG_STARTEND support. Compile with NO_REGEX=NeedsStartEnd"
9991004
#endif

0 commit comments

Comments
 (0)