This is the mail archive of the
mailing list for the libstdc++ project.
Re: Avoiding string segfaults
- To: Yves BAILLY <kafka dot fr at netcourrier dot com>
- Subject: Re: Avoiding string segfaults
- From: Phil Edwards <pedwards at disaster dot jaj dot com>
- Date: Thu, 12 Jul 2001 17:22:07 -0400
- Cc: libstdc++ at gcc dot gnu dot org
- References: <0107122243270D.email@example.com>
On Thu, Jul 12, 2001 at 10:43:27PM +0200, Yves BAILLY wrote:
> This is my first post on this list. Sorry if it's not the right place
> for my query.
It's the right place for anything dealing with libstdc++-v3.
> This occures
> when I try to build a string from a null pointer.
> Looking at the code for the string class (basic_string actually), I didn't
> find any check against a null-pointer when building a string from a
> Is this the wanted behaviour ? Would it be bad to build an empty string
> from a null pointer ?
Strictly speaking, it's undefined behavior when you try to do that (based on
[21.3.1]/9 and [126.96.36.199]/1 of the standard). We could check for NULL in
the constructor (it's a QoI issue), but that would slow down all programs
everywhere that construct basic_string's from char*'s.
This is one of those places where I've thought about conditionally compiling
extra code into the headers when --enable-debug has been passed at configure
time, but I've never sat down and worked out a proposal.
Would I had phrases that are not known, utterances that are strange, in
new language that has not been used, free from repetition, not an utterance
which has grown stale, which men of old have spoken.
- anonymous Egyptian scribe, c.1700 BC