From 46dc31452002b52a01d60656dfc25a82e3e2400a Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 17 Oct 2026 17:09:16 -1000 Subject: 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. --- source/ui-refs.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source/ui-refs.c') 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(); -- cgit