git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git Mailing List <git@vger.kernel.org>,
	Derrick Stolee <dstolee@microsoft.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] gc: fix cast in compare_tasks_by_selection()
Date: Tue, 17 Nov 2020 17:30:11 -0500	[thread overview]
Message-ID: <20201117223011.GA642234@coredump.intra.peff.net> (raw)
In-Reply-To: <d80423b7-c89d-99a2-ce49-8308822f7769@web.de>

On Tue, Nov 17, 2020 at 10:59:49PM +0100, René Scharfe wrote:

> 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).

I checked the caller here, and indeed, it's passing an array-of-struct
so your patch is doing the right thing (not that I doubted it, but
that's what review is for).

This qsort void-pointer convention seems to create a lot of confusion
(not just the lack of type-safety, but the fact that it's getting a
pointer to the element). I felt like we had a discussion about this a
while ago, and indeed, I found:

  https://lore.kernel.org/git/7b95417a-c8fb-4f1e-cb09-c36804a3a4d0@web.de/

The whole sub-thread is worth reading, but the macro you arrived at in:

  https://lore.kernel.org/git/c141fb44-904f-e8b6-119f-7d2d6bcfd81a@web.de/

seems pretty reasonable.

-Peff

      reply	other threads:[~2020-11-17 22:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-17 21:59 [PATCH] gc: fix cast in compare_tasks_by_selection() René Scharfe
2020-11-17 22:30 ` Jeff King [this message]

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201117223011.GA642234@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).