]> git.ipfire.org Git - thirdparty/git.git/commitdiff
gc: fix cast in compare_tasks_by_selection()
authorRené Scharfe <l.s.r@web.de>
Tue, 17 Nov 2020 21:59:49 +0000 (22:59 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Nov 2020 22:15:58 +0000 (14:15 -0800)
compare_tasks_by_selection() is used with QSORT and gets passed pointers
to the elements of "static struct maintenance_task tasks[]".  It casts
the *addresses* of these passed pointers to element pointers, though,
and thus effectively compares some unrelated values from the stack.  Fix
the casts to actually compare array elements.

Detected by USan (make SANITIZE=undefined test).

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/gc.c

index 3d258b60c2db2c736046f182afc096a45d2556ed..bc25ad52c7dc92e914d6f815b2209f4c26571cc4 100644 (file)
@@ -1253,10 +1253,8 @@ static struct maintenance_task tasks[] = {
 
 static int compare_tasks_by_selection(const void *a_, const void *b_)
 {
-       const struct maintenance_task *a, *b;
-
-       a = (const struct maintenance_task *)&a_;
-       b = (const struct maintenance_task *)&b_;
+       const struct maintenance_task *a = a_;
+       const struct maintenance_task *b = b_;
 
        return b->selected_order - a->selected_order;
 }