From: "René Scharfe" <l.s.r@web.de>
To: Git Mailing List <git@vger.kernel.org>
Cc: Derrick Stolee <dstolee@microsoft.com>,
Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] gc: fix cast in compare_tasks_by_selection()
Date: Tue, 17 Nov 2020 22:59:49 +0100 [thread overview]
Message-ID: <d80423b7-c89d-99a2-ce49-8308822f7769@web.de> (raw)
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>
---
builtin/gc.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/builtin/gc.c b/builtin/gc.c
index 5cd2a43f9f..986b760b30 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1213,10 +1213,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;
}
--
2.29.2
next reply other threads:[~2020-11-17 22:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-17 21:59 René Scharfe [this message]
2020-11-17 22:30 ` [PATCH] gc: fix cast in compare_tasks_by_selection() Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d80423b7-c89d-99a2-ce49-8308822f7769@web.de \
--to=l.s.r@web.de \
--cc=dstolee@microsoft.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.