public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
Cc: Tom Tromey <tom@tromey.com>,  Simon Marchi <simon.marchi@polymtl.ca>
Subject: Re: [PATCH 1/2] gdb: check for empty offsets vector in inherit_abstract_dies
Date: Fri, 21 Oct 2022 12:02:41 -0600	[thread overview]
Message-ID: <87k04tawce.fsf@tromey.com> (raw)
In-Reply-To: <bc6c4d63-a288-d396-e6de-124c3871b120@polymtl.ca> (Simon Marchi via Gdb-patches's message of "Fri, 21 Oct 2022 11:46:51 -0400")

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

>> This subsequent loop does stuff like:
>> 
>> while (offsetp < offsets_end
>> && *offsetp < origin_child_die->sect_off)
>> offsetp++;
>> 
>> which in this scenario would be comparing null pointers using "<"?

Simon> Is it undefined behavior to compre two null pointers (both offsetp and
Simon> offset_end would be nullptr or both wouldn't be nullptr)?  At least
Simon> clang's UB sanitizer doesn't panic.

I don't know but it's certainly weird.

>> I'm guessing this whole loop should be hoisted into the 'if'.

Simon> I don't understand enough what the code does to be convinced this would
Simon> be a correct change.

Any real work done in the loop is conditional on checking 'offsetp',
which will always be NULL in this scenario.

The loop also updates origin_child_die, but that's not used after the
loop completes.

So while I also think the code is super obscure, it also seems correct
to do this hoisting.

Simon> Note that the following patch changes this to use iterators, so it makes
Simon> the worry about comparing null pointers being undefined behavior go
Simon> away.  It becomes comparing offsets.end() with offsets.end().

Yeah.

Tom

      reply	other threads:[~2022-10-21 18:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-21 13:21 Simon Marchi
2022-10-21 13:21 ` [PATCH 2/2] gdb: make inherit_abstract_dies use vector iterators Simon Marchi
2022-10-21 18:04   ` Tom Tromey
2022-10-21 18:04     ` Tom Tromey
2022-10-21 18:26     ` Simon Marchi
2022-10-21 15:35 ` [PATCH 1/2] gdb: check for empty offsets vector in inherit_abstract_dies Tom Tromey
2022-10-21 15:35   ` Tom Tromey
2022-10-21 15:46   ` Simon Marchi
2022-10-21 18:02     ` Tom Tromey [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

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

  git send-email \
    --in-reply-to=87k04tawce.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /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 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).