summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2020-11-17 21:59:49 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-11-18 22:15:58 (GMT)
commita1c74791d5ffaa6d723abb14cebf556499c3c4cb (patch)
tree172fbfdecf391c76ecd71d6ca78f24d366e8aa86 /builtin
parentfaefdd61ec7c7f6f3c8c9907891465ac9a2a1475 (diff)
downloadgit-a1c74791d5ffaa6d723abb14cebf556499c3c4cb.zip
git-a1c74791d5ffaa6d723abb14cebf556499c3c4cb.tar.gz
git-a1c74791d5ffaa6d723abb14cebf556499c3c4cb.tar.bz2
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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/gc.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/builtin/gc.c b/builtin/gc.c
index 3d258b6..bc25ad5 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;
}