This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/42857] New: std::istream::ignore(std::streamsize n) calls unnecessary underflow
- From: "tommi at tntnet dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 24 Jan 2010 19:46:02 -0000
- Subject: [Bug libstdc++/42857] New: std::istream::ignore(std::streamsize n) calls unnecessary underflow
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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