public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "bugs at mm dot beanwood.com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/42857] std::istream::ignore(std::streamsize n) calls unnecessary underflow
Date: Sun, 24 Feb 2013 22:05:00 -0000	[thread overview]
Message-ID: <bug-42857-4-yUeTlmkOfn@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-42857-4@http.gcc.gnu.org/bugzilla/>


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

Andrew Ayer <bugs at mm dot beanwood.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugs at mm dot beanwood.com

--- Comment #4 from Andrew Ayer <bugs at mm dot beanwood.com> 2013-02-24 22:05:26 UTC ---
(In reply to comment #2)
> I want to understand how critical this additional underflow is,
> performance-wise

There are also correctness implications: what if you're trying to ignore
all the bytes you know are available to be read without blocking?  Then
the extra underflow blocks, possibly forever if the program is prevented
from taking action that would result in the underflow completing.
I got bitten by this because I was trying to ignore data from a socket.

Note that the standard has similar language for read(char_type*,
streamsize) ("either of the following conditions") but the library in
effect checks for n characters being reached before checking for eof:
if you read() exactly the number of characters left in the stream,
eofbit is not set.  So the library isn't currently consistent across
all the various istream functions.

I would argue that the current behavior of ignore() is actually contrary
to the standard.  If the standard says "until any" then ignore()
needs to terminate when n characters have been extracted.  But if it
first checks for eof and blocks forever, then it doesn't terminate.
Perhaps this is why getline explicitly mentions the order: in that case
the standard really does want eof to be checked first.


  parent reply	other threads:[~2013-02-24 22:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-42857-4@http.gcc.gnu.org/bugzilla/>
2011-12-22  0:56 ` paolo.carlini at oracle dot com
2013-02-24 22:05 ` bugs at mm dot beanwood.com [this message]
2014-04-18 16:19 ` cubbi at cubbi dot org
2014-07-23 21:47 ` bugs at mm dot beanwood.com
2020-11-10 23:46 ` ncm at cantrip dot org
2020-11-11  0:01 ` redi at gcc dot gnu.org
2020-11-11  0:06 ` ncm at cantrip dot org
2020-11-11  0:24 ` redi at gcc dot gnu.org
2010-01-24 19:46 [Bug libstdc++/42857] New: " tommi at tntnet dot org
2010-01-27 21:10 ` [Bug libstdc++/42857] " paolo dot carlini at oracle dot com
2010-09-20 12:15 ` paolo dot 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=bug-42857-4-yUeTlmkOfn@http.gcc.gnu.org/bugzilla/ \
    --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).