From a1c74791d5ffaa6d723abb14cebf556499c3c4cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Tue, 17 Nov 2020 22:59:49 +0100 Subject: [PATCH] gc: fix cast in compare_tasks_by_selection() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- builtin/gc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 3d258b60c2..bc25ad52c7 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -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; }