libstdc++/8071: basic_ostream::operator<<(streambuf*) loops forever if streambuf::underflow() leaves gptr() NULL

lennox@cs.columbia.edu lennox@cs.columbia.edu
Fri Sep 27 09:30:00 GMT 2002


>Number:         8071
>Category:       libstdc++
>Synopsis:       basic_ostream::operator<<(streambuf*) loops forever if streambuf::underflow() leaves gptr() NULL
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Sep 27 08:56:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     lennox@cs.columbia.edu
>Release:        gcc-3.1
>Organization:
>Environment:
sparc-sun-solaris2.8
>Description:
According to my reading of the C++ standard, a subclass of std::basic_streambuf<> is allowed to declare its uflow() and underflow() functions such that they don't fill their buffers.  This is useful, for instance, if the streambuf is a wrapper around another type that does its own buffering.

However, libstdc++'s basic_ostream::operator<<(streambuf*) operator loops forever when passed such a streambuf, repeatedly invoking underflow() and never actually extracting any data from the buffer.

I've attached some code written by Matt Austern, and published in the C++ Users Journal.  This code creates a streambuf and istream that wraps a C FILE*, so I/O can safely be intermixed on the two types.  Using operator<< on the syncbuf this code declares illustrates the problem.
>How-To-Repeat:
Compile the attached code.  (It looks like gnats won't allow me to attach more than one file in the initial bug report, so I've just attached the header.  I'll attach the body momentarily.)
>Fix:
I think the fix needs to change basic_streambuf::__copy_streambufs, but I'm not sure exactly what the fix should be.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="syncstream.h"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="syncstream.h"

Ly8gLSotIEMrKyAtKi0KCi8qIENvZGUgYnkgTWF0dCBBdXN0ZXJuLCBmcm9tIHRoZSBDL0MrKyBV
c2VycyBKb3VybmFsOgogKiA8aHR0cDovL3d3dy5jdWouY29tL2V4cGVydHMvMTgxMS9hdXN0ZXJu
Lmh0bT90b3BpYz1leHBlcnRzPgogKiBNaW5vciB0d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RyKTsKfQoKaW50IHN5bmNidWY6OnBi
YWNrZmFpbChpbnQgYykgewogICByZXR1cm4gYyAhPSBFT0YgPyB1bmdldGMoYywgZnB0cikgOiBF
T0Y7Cn0KCmludCBzeW5jYnVmOjpzeW5jKCkgewogICByZXR1cm4gZmZsdXNoKGZwdHIpOwp9CgoK
CmNsYXNzIGlzeW5jc3RyZWFtCiAgIDogcHVibGljIHN0ZDo6aXN0cmVhbSB7CnB1YmxpYzoKICAg
aXN5bmNzdHJlYW0oKQogICAgICA6IHN0ZDo6aXN0cmVhbSgmYnVmKSwgYnVmKDApIHt9CiAgIGlz
eW5jc3RyZWFtKEZJTEUqIGZwdHIpCiAgICAgIDogc3RkOjppc3RyZWFtKCZidWYpLCBidWYoZnB0
cikge30KICAgc3luY2J1ZiogcmRidWYoKSBjb25zdCB7CiAgICAgIHJldHVybiBjb25zdF9jYXN0
PHN5bmNidWYqPigmYnVmKTsKICAgfQpwcml2YXRlOgogICBzeW5jYnVmIGJ1ZjsKfTsKCiNlbmRp
Zgo=



More information about the Gcc-bugs mailing list