public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Ruslan Kabatsayev <b7.10110111@gmail.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH][RFC] Avoid indexing std::vector past the end
Date: Sat, 30 Dec 2017 00:51:00 -0000	[thread overview]
Message-ID: <608baf012f787e3b74445e3ef9062b93@polymtl.ca> (raw)
In-Reply-To: <1514476903-5206-1-git-send-email-b7.10110111@gmail.com>

On 2017-12-28 11:01, Ruslan Kabatsayev wrote:
> Hello all,
> 
> On my system I have added some asserts into GCC's stl_vector.h, which 
> check for
> various mistakes like out of bounds access, call to std::vector::front 
> on empty
> vector etc. to debug my own projects. After I built GDB with such
> modifications, I've noticed that in some cases it accesses some vectors 
> out of
> bound, namely element one past the end. Effectively the code is 
> something like
> `auto*p=&someVector[someVector.size()];`, which, although may seem 
> legitimate
> on the first glance since it simply takes address, is still Undefined 
> Behavior
> according to the C++ Standard (see e.g. [1] and links in that page).
> 
> So I wonder whether GDB deliberately exploits undefined behavior here 
> knowing
> that GCC might give(?) some guarantee that this will always work as 
> intended,
> or it's simply a mistake, and my patch would be OK.
> 
> [1]: https://stackoverflow.com/a/27069592/673852
> 
> Regards,
> Ruslan

Hi Ruslan,

Thanks for finding and reporting this.  We certainly don't want to rely 
on any compiler-specific undefined behavior, this is a mistake.

The patch looks good to me, it's just missing a ChangeLog entry.

Simon

      reply	other threads:[~2017-12-30  0:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-28 16:01 Ruslan Kabatsayev
2017-12-30  0:51 ` Simon Marchi [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=608baf012f787e3b74445e3ef9062b93@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=b7.10110111@gmail.com \
    --cc=gdb-patches@sourceware.org \
    /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).