Skip to content

Commit a1c7479

Browse files
rscharfegitster
authored andcommitted
gc: fix cast in compare_tasks_by_selection()
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent faefdd6 commit a1c7479

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

builtin/gc.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,10 +1253,8 @@ static struct maintenance_task tasks[] = {
12531253

12541254
static int compare_tasks_by_selection(const void *a_, const void *b_)
12551255
{
1256-
const struct maintenance_task *a, *b;
1257-
1258-
a = (const struct maintenance_task *)&a_;
1259-
b = (const struct maintenance_task *)&b_;
1256+
const struct maintenance_task *a = a_;
1257+
const struct maintenance_task *b = b_;
12601258

12611259
return b->selected_order - a->selected_order;
12621260
}

0 commit comments

Comments
 (0)