diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Sort an empty list without handing qsort a null
Every list sorted here is null until its first entry, and C leaves a
null base undefined even with nothing to sort. glibc declares it nonnull
and its UBSan build aborted the stats page of a repository with no
commits in the window, which the Linux matrix caught.
Diffstat (limited to 'source/shared.h')
| -rw-r--r-- | source/shared.h | 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 12 insertions, 0 deletions
diff --git a/source/shared.h b/source/shared.h index e22eb57..2bf305d 100644 --- a/source/shared.h +++ b/source/shared.h @@ -140,4 +140,16 @@ extern int cgit_valid_rev(const char *rev); */ extern int cgit_notes_ref_usable(const char *notes_ref); +/* + * qsort for a list that may be empty. C leaves a null base undefined even + * with nothing to sort, and glibc declares it nonnull, while the lists here + * stay null until their first entry. + */ +static inline void cgit_qsort(void *base, size_t n, size_t size, + int (*cmp)(const void *, const void *)) +{ + if (n) + qsort(base, n, size, cmp); +} + #endif // CGIT_SHARED_H |
