Bug 8127 - cout << cin.rdbuf() causes infinite loop
Summary: cout << cin.rdbuf() causes infinite loop
Status: RESOLVED DUPLICATE of bug 6745
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 3.1
: P3 normal
Target Milestone: ---
Assignee: Paolo Carlini
Depends on:
Reported: 2002-10-02 13:56 UTC by Jonathan Lennox
Modified: 2003-06-12 00:15 UTC (History)
2 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:

test-rdbuf.cxx (83 bytes, application/octet-stream)
2003-05-21 15:17 UTC, Jonathan Lennox

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Lennox 2002-10-02 13:56:00 UTC
The attached trivial implementation of 'cat' goes into an infinite loop when compiled with GCC 3.1.

This may be another instance of bug libstdc++/8071, interacting with libstdc++/7744.  However, it seems to me that this is a much more significant example of the bug.

The problem arises in basic_streambuf::__copy_streambufs.
This function calls __sbout->in_avail() to get the number of characters that it can read.  If this returns 0, the function loops forever calling  __sbout->sputn(__sbin->gptr(), 0).

This is a regression from gcc 2.95.2, which executes this code correctly.

(I haven't tested this code with GCC 3.3 mainline, but I don't see anything in GNATS or viewcvs which would indicate that this code has changed since 3.1.)



Compile the attached program, and run it with standard input coming from somewhere.  E.g.:

grandcentral $ g++-2.95.2 -Wall -g -O2  -o test-rdbuf test-rdbuf.cxx
grandcentral $ ./test-rdbuf < /etc/nodename 
grandcentral $ g++ -Wall -g -O2  -o test-rdbuf test-rdbuf.cxx
grandcentral $ ./test-rdbuf < /etc/nodename 
Comment 1 Paolo Carlini 2002-10-06 05:03:04 UTC
*** This bug has been marked as a duplicate of 6745 ***
Comment 2 Paolo Carlini 2002-11-19 01:36:29 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: I'm closing it: by now we understand those issues, which are
    fixed as far as correctness in concerned.