Article View: gnu.g++.bug
Article #252bottomless recursion in stream output
From: Doug Moore
Date: Mon, 13 Apr 1992 22:49
Date: Mon, 13 Apr 1992 22:49
61 lines
2922 bytes
2922 bytes
Consider the following program:
---- cut here ---------
#include <iostream.h>
main()
{
for(int i = 0 ; i < 396 ; i++)
{
cerr << "i = " << i << "\n";
cerr << "AAAAAAAAAAAA\n";
}
}
---- cut here ---------
Seems innocent, doesn't it?
Well, if one compiles it with g++2.1*, using a version of libg++-2.0
compiled with g++2.1* on a sparc2, sunos 4.1, Sun loader, collect2,
and one runs it, it dies with a bottomless recursion. The last thing printed is
i = 395
and the death occurs in the attempt to print the newline at the end of
that line. Significantly, that newline happens to be the 8193rd
character of output produced by this program.
The bottomless recursion has the following (partial) backtrace as it
begins its descent into the void:
#0 filebuf::overflow (this=0x1a5f8, c=10) at filebuf.C:213
#1 0x11674 in streambuf::sputc (this=0x1a5f8, c=10)
at /marsh/comp212/gnu/libg++-2.0/libg++/iostream/streambuf.h:278
#2 0x5718 in filebuf::overflow (this=0x1a5f8, c=10) at filebuf.C:261
#3 0x11674 in streambuf::sputc (this=0x1a5f8, c=10)
at /marsh/comp212/gnu/libg++-2.0/libg++/iostream/streambuf.h:278
#4 0x5718 in filebuf::overflow (this=0x1a5f8, c=10) at filebuf.C:261
#5 0x1199c in streambuf::sputn (this=0x1a5f8, s=0x2299 "", n=1) at streambuf.C:46
#6 0x68d0 in filebuf::sputn (this=0x1a5f8, s=0x2298 "\n", n=1) at filebuf.C:546
#7 0xa98c in operator<< (stream=@0x1a694, s=0x2298 "\n") at iostream.C:506
#8 0x2310 in main () at bug.cc:7
and here is the (routine) compiler output from compiling the program:
c++ -g -Wall -v bug.cc
Reading specs from /marsh/comp212/lib/gcc-lib/sun4/2.1/specs
gcc version 2.1
/marsh/comp212/lib/gcc-lib/sun4/2.1/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -g -Wall bug.cc /usr/tmp/cca25242.i
GNU CPP version 2.1 (sparc)
/marsh/comp212/lib/gcc-lib/sun4/2.1/cc1plus /usr/tmp/cca25242.i -quiet -dumpbase bug.cc -g -Wall -version -o /usr/tmp/cca25242.s
GNU C++ version 2.1 (sparc) compiled by GNU C version 2.1.
as -o bug.o /usr/tmp/cca25242.s
/marsh/comp212/lib/gcc-lib/sun4/2.1/ld -e start -dc -dp /lib/crt0.o -L/marsh/comp212/lib/gcc-lib/sun4/2.1/ -L/marsh/comp212/lib/ bug.o -lg++ -lm -lgcc -lc -lg -lgcc
Compilation finished at Mon Apr 13 17:48:29
I wish I could suggest a patch, but the code is too opaque for me.
Doug Moore (dougm@cs.rice.edu)
* with Tiemann and Stump patches applied
Technical Details
Message-ID:
<9204132249.AA08205@cs.rice.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.rice.edu!dougmShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.rice.edu!dougm From: dougm@cs.rice.edu (Doug Moore) Subject: bottomless recursion in stream output Message-ID: <9204132249.AA08205@cs.rice.edu> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Mon, 13 Apr 1992 22:49:13 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 63