diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce 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 '')
-rw-r--r--source/ui-refs.c12
1 file changed, 6 insertions, 6 deletions
diff --git a/source/ui-refs.c b/source/ui-refs.c
index 890a959..38a5773 100644
--- a/source/ui-refs.c
+++ b/source/ui-refs.c
@@ -246,9 +246,9 @@ static void print_branches_page(int pagesize)
print_branch_header();
collect_branches(&list);
- qsort(list.refs, list.count, sizeof(*list.refs), cmp_date);
+ cgit_qsort(list.refs, list.count, sizeof(*list.refs), cmp_date);
if (ctx.repo->branch_sort == 0)
- qsort(list.refs, list.count, sizeof(*list.refs), cmp_name);
+ cgit_qsort(list.refs, list.count, sizeof(*list.refs), cmp_name);
page = page_bounds(pagesize, list.count);
@@ -271,7 +271,7 @@ static void print_tags_page(int pagesize)
collect_tags(&list);
if (list.count == 0)
return;
- qsort(list.refs, list.count, sizeof(*list.refs), cmp_date);
+ cgit_qsort(list.refs, list.count, sizeof(*list.refs), cmp_date);
page = page_bounds(pagesize, list.count);
@@ -300,9 +300,9 @@ void cgit_print_branches(int maxcount)
// The date sort covers the list, the name sort only the rows about to
// be shown, so the section holds the newest branches rather than the
// first ones by name.
- qsort(list.refs, list.count, sizeof(*list.refs), cmp_date);
+ cgit_qsort(list.refs, list.count, sizeof(*list.refs), cmp_date);
if (ctx.repo->branch_sort == 0)
- qsort(list.refs, maxcount, sizeof(*list.refs), cmp_name);
+ cgit_qsort(list.refs, maxcount, sizeof(*list.refs), cmp_name);
for (i = 0; i < maxcount; i++)
print_branch(list.refs[i]);
@@ -322,7 +322,7 @@ void cgit_print_tags(int maxcount)
collect_tags(&list);
if (list.count == 0)
return;
- qsort(list.refs, list.count, sizeof(*list.refs), cmp_date);
+ cgit_qsort(list.refs, list.count, sizeof(*list.refs), cmp_date);
if (maxcount <= 0 || maxcount > list.count)
maxcount = list.count;
print_tag_header();