This is the mail archive of the
mailing list for the libstdc++ project.
Re: [patch][google/integration] Add lightweight checks to vector::begin et. al. (issue4973065)
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Jonathan Wakely <jwakely dot gcc at gmail dot com>, Paul Pluzhnikov <ppluzhnikov at google dot com>, Diego Novillo <dnovillo at google dot com>, libstdc++ at gcc dot gnu dot org, reply at codereview dot appspotmail dot com
- Date: Wed, 7 Sep 2011 10:34:37 +0100
- Subject: Re: [patch][google/integration] Add lightweight checks to vector::begin et. al. (issue4973065)
- References: <20110906162854.5C60B190B10@elbrus2.mtv.corp.google.com> <CALoOobMDWiqBigQupbK0QzQ=RFAcuV=zvkJb+V7zQ4SqJVqOKQ@mail.gmail.com> <CAH6eHdSAYipPavt1iXcEV5nRKndweW50afyN2f_8xEwpCRRy9A@mail.gmail.com>
On Tuesday 06 September 2011 23:09:17, Jonathan Wakely wrote:
> On 6 September 2011 22:58, Paul Pluzhnikov wrote:
> > On Tue, Sep 6, 2011 at 2:51 PM, Jonathan Wakely <firstname.lastname@example.org> wrote:
> >> I don't mean for vector::begin and the other functions in that patch,
> >> I mean in general for member functions of any type. There are plenty
> >> of functions that wouldn't crash when called through a null pointer.
> >> But even std:vector has member functions like that, such as max_size.
> > Right. (We might tweak the compiler to automagically insert that assert
> > in non-omitimized builds ;-)
> Heh :-)
> Have you considered a compiler option to make 'delete v' zero out the
> pointer, so that any following use of it gives an immediate segfault?
> That would be conforming (the value of delete's operand is unspecified
> after the operation), but would only help if the same pointer is used,
> rather than another object with the same value. I don't know of any
> compiler that does that, but have wondered if it would be useful for
> debugging some cases.
Zeroing out would hide bugs; there's lots of code that does
You'd not see the bug that way. Making 'delete v' clobber the pointer
with 0xdeadbeef or ~0 instead would be better.