libstdc++/8127: cout << cin.rdbuf() causes infinite loop
Wed Oct 2 13:56:00 GMT 2002

>Number:         8127
>Category:       libstdc++
>Synopsis:       cout << cin.rdbuf() causes infinite loop
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Oct 02 13:56:00 PDT 2002
>Release:        gcc-3.1
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 

Content-Type: application/octet-stream; name="test-rdbuf.cxx"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test-rdbuf.cxx"


More information about the Gcc-bugs mailing list