This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++/9424: i/ostream::operator>>/<<(streambuf*) drops characters
- From: peturr02 at ru dot is
- To: gcc-gnats at gcc dot gnu dot org
- Date: 23 Jan 2003 18:58:16 -0000
- Subject: libstdc++/9424: i/ostream::operator>>/<<(streambuf*) drops characters
- Reply-to: peturr02 at ru dot is
>Number: 9424
>Category: libstdc++
>Synopsis: i/ostream::operator>>/<<(streambuf*) drops characters
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Jan 23 19:06:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: peturr02@ru.is
>Release: gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
basic_istream<>::operator>>(basic_streambuf<>*) and basic_ostream<>::operator<<(basic_streambuf<>*) drop characters on the floor by extracting characters from the source before they have been successfully inserted into the sink.
This seems to happen only if the source is unbuffered, if the source is buffered, extraction happens after insertion as required.
>How-To-Repeat:
See attachment.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="streambufcopybug2.cc"
Content-Disposition: inline; filename="streambufcopybug2.cc"
#include <streambuf>
#include <istream>
#include <ostream>
#include <cstring>
#undef NDEBUG
#include <cassert>
using namespace std;
class Outbuf : public streambuf
{
char buf[1];
public:
Outbuf()
{
setp(buf, buf + 1);
}
int_type overflow(int_type c)
{
int_type eof = traits_type::eof();
if (pptr() < epptr())
{
if (traits_type::eq_int_type(c, eof))
return traits_type::not_eof(c);
*pptr() = traits_type::to_char_type(c);
pbump(1);
return c;
}
return eof;
}
};
class Inbuf : public streambuf
{
static const char buf[];
const char* current;
int size;
public:
Inbuf()
{
current = buf;
size = strlen(buf);
}
int_type underflow()
{
if (current < buf + size)
return traits_type::to_int_type(*current);
return traits_type::eof();
}
int_type uflow()
{
if (current < buf + size)
return traits_type::to_int_type(*current++);
return traits_type::eof();
}
};
const char Inbuf::buf[] = "0123456789";
int main()
{
Inbuf inbuf1;
istream is (&inbuf1);
Outbuf outbuf1;
is >> &outbuf1;
assert(inbuf1.sgetc() == '1');
Outbuf outbuf2;
ostream os (&outbuf2);
Inbuf inbuf2;
os << &inbuf2;
assert(inbuf2.sgetc() == '1');
return 0;
}