public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "phil at mitre dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/26458] Passing a NULL char* into output stream now breaks the output stream
Date: Fri, 24 Feb 2006 18:48:00 -0000	[thread overview]
Message-ID: <20060224184556.11049.qmail@sourceware.org> (raw)
In-Reply-To: <bug-26458-12260@http.gcc.gnu.org/bugzilla/>



------- Comment #2 from phil at mitre dot org  2006-02-24 18:45 -------
Subject: RE:  Passing a NULL char* into output stream now breaks the output
stream

Thanks for the quick response.  This came up when some old systems were
ported from Solaris using gcc-2.9.5 or so and out output files just
stopped growing.  Took a couple days of detailed debugging to track it
down to a low-level string class...

In any event, my experience is that developers tend not to assert the
status of the stream operators every time they use them, especially
output streams.  In general, with almost any output descriptor or
stream, you use it correctly or not to your peril, subject to core
dumps and the like.  However, this behavior seems to expect that all
developers will do the right thing and always check stream state after
each << use (never mind if you string several together).  But the
reason they got into this state to begin with is because they did
something wrong, sending NULL where they shouldn't, so how can you
expect, if they did that, that they would bother to check the ostream
operator.

So my feeling is that the effect of doing this should be one of the
following:

1. allow << for NULL of known type by doing nothing; if (NULL)
return...
2. seg fault for making an ostream deref a NULL 

Otherwise, there's great potential that the output stream (the data)
will become corrupted, even if you manage to check it state.  For
example:

cout << "hello " << val1 << " is " << val2 << " here today?" << endl;
assert(!cout.good());

It's almost impossible to determine, even if you know the state is bad,
how much data was successfully sent into the stream before it crapped
out.  On one level you're doing a nice thing by not crashing the
program, but on another it seems unlikely you'll be able to recover the
stream, by perhaps filling in missing pieces correctly, so you might as
well crash.

        Thanks again for the response...

                phil


Phil Brown
Lead Software Systems Engineer
Mitre CAASD
phil@mitre.org

Perception is nine-tenths of the flaw.


>-----Original Message-----
>From: pcarlini at suse dot de [mailto:gcc-bugzilla@gcc.gnu.org] 
>Sent: Friday, February 24, 2006 11:53 AM
>To: Brown, Phil
>Subject: [Bug libstdc++/26458] Passing a NULL char* into 
>output stream now breaks the output stream
>
>
>
>------- Comment #1 from pcarlini at suse dot de  2006-02-24 
>16:53 -------
>The change is certainly intended and the important point is 
>that is not true
>that there is no indication of the failure, quite to the 
>contrary the badbit is
>set. Try changing your test like this:
>
>  char *str = NULL;
>  cout << "Hello " << str;
>
>  assert( !cout.good() );
>  cout.clear();
>
>  cout << " there" << endl;
>
>  assert( cout.good() );
>
>  cout << "still dead?" << endl;
>
>  assert( cout.good() );
>
>
>-- 
>
>pcarlini at suse dot de changed:
>
>           What    |Removed                     |Added
>---------------------------------------------------------------
>-------------
>             Status|UNCONFIRMED                 |RESOLVED
>          Component|c++                         |libstdc++
>         Resolution|                            |INVALID
>
>
>http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26458
>
>------- You are receiving this mail because: -------
>You reported the bug, or are watching the reporter.
>


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26458


  parent reply	other threads:[~2006-02-24 18:45 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-24 16:53 [Bug c++/26458] New: " phil at mitre dot org
2006-02-24 17:25 ` [Bug libstdc++/26458] " pcarlini at suse dot de
2006-02-24 18:48 ` phil at mitre dot org [this message]
2006-02-24 18:55 ` phil at mitre dot org
2006-02-24 18:59 ` pinskia at gcc dot gnu dot org
2006-02-24 19:04 ` phil at mitre dot org
2006-02-24 20:40 ` pcarlini at suse dot de
2006-02-24 20:45 ` phil at mitre dot org
2006-02-24 21:04 ` pcarlini at suse dot de
2006-02-24 21:15 ` phil at mitre dot org
2006-02-24 21:32 ` pcarlini at suse dot de
     [not found] <bug-26458-4@http.gcc.gnu.org/bugzilla/>
2011-03-13  7:28 ` ian at airs dot com
2011-03-13 13:11 ` paolo.carlini at oracle dot com

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=20060224184556.11049.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.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).