public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: peturr02@ru.is To: gcc-gnats@gcc.gnu.org Subject: libstdc++/9424: i/ostream::operator>>/<<(streambuf*) drops characters Date: Thu, 23 Jan 2003 19:06:00 -0000 [thread overview] Message-ID: <20030123185816.4751.qmail@sources.redhat.com> (raw) >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; }
next reply other threads:[~2003-01-23 19:06 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2003-01-23 19:06 peturr02 [this message] 2003-02-26 0:34 paolo 2003-02-26 9:36 Pétur Runólfsson 2003-03-07 19:56 Nathan Myers 2003-03-07 21:26 Paolo Carlini 2003-03-09 11:27 paolo
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=20030123185816.4751.qmail@sources.redhat.com \ --to=peturr02@ru.is \ --cc=gcc-gnats@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: linkBe 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).