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



On 2022-10-21 11:35, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> +  if (!offsets.empty ())
> Simon> +    {
> Simon> +      std::sort (offsets.begin (), offsets.end ());
> Simon> +      sect_offset *offsets_end = offsets.data () + offsets.size ();
> Simon> +      for (sect_offset *offsetp = offsets.data () + 1;
> Simon> +	   offsetp < offsets_end;
> Simon> +	   offsetp++)
> Simon> +	if (offsetp[-1] == *offsetp)
> Simon> +	  complaint (_("Multiple children of DIE %s refer "
> Simon> +		       "to DIE %s as their abstract origin"),
> Simon> +		     sect_offset_str (die->sect_off),
> Simon> +		     sect_offset_str (*offsetp));
> Simon> +    }
>  
> Simon>    sect_offset *offsetp = offsets.data ();
> Simon> +  sect_offset *offsets_end = offsets.data () + offsets.size ();
> Simon>    die_info *origin_child_die = origin_die->child;
> Simon>    while (origin_child_die != nullptr && origin_child_die->tag != 0)
> Simon>      {
> 
> 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 "<"?

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

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

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

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

Simon

  parent reply	other threads:[~2022-10-21 15:46 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 [this message]
2022-10-21 18:02     ` Tom Tromey

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=bc6c4d63-a288-d396-e6de-124c3871b120@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.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 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).