public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/42857]  New: std::istream::ignore(std::streamsize n) calls unnecessary underflow
@ 2010-01-24 19:46 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
  0 siblings, 2 replies; 10+ messages in thread
From: tommi at tntnet dot org @ 2010-01-24 19:46 UTC (permalink / raw)
  To: gcc-bugs

When ignoring the number of bytes available in a streambuf using
std::istream::ignore, ignore calls underflow. This should not happen. I feel
the easiest way to reproduce it is to look at strace output when ignoring bytes
from ifstream:

#include <iostream>
#include <fstream>

int main(int argc, char* argv[])
{
  std::ifstream in(argv[0]);
  in.get(); // trigger filling of input buffer by calling underflow
  in.ignore(in.rdbuf()->in_avail());  // this triggers another underflow
}

The strace output shows, that 2 calls to read with 8191 bytes occures. When
ignoring one byte less and then another byte, only one read is done:

#include <iostream>
#include <fstream>

int main(int argc, char* argv[])
{
  std::ifstream in(argv[0]);
  in.get(); // trigger filling of input buffer
  in.ignore(in.rdbuf()->in_avail() - 1);
  in.ignore(1); // this does not trigger underflow
}


-- 
           Summary: std::istream::ignore(std::streamsize n) calls
                    unnecessary underflow
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tommi at tntnet dot org
GCC target triplet: i486-linux-gnu


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


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-11-11  0:24 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-42857-4@http.gcc.gnu.org/bugzilla/>
2011-12-22  0:56 ` [Bug libstdc++/42857] std::istream::ignore(std::streamsize n) calls unnecessary underflow paolo.carlini at oracle dot com
2013-02-24 22:05 ` bugs at mm dot beanwood.com
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

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).