This is the mail archive of the mailing list for the libstdc++ project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Avoiding string segfaults

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
> char*.
> 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 []/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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]