This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
bug in strstream since Apr 1998
- To: bug-gcc at gnu dot org
- Subject: bug in strstream since Apr 1998
- From: Joseph Heled <joseph at itginc dot com>
- Date: Thu, 16 Mar 2000 16:24:38 -0800
- CC: Alexandre Oliva <oliva at dcc dot unicamp dot br>
Hi there,
I am writing again regarding a bug I reported in 1998, which results in
strstream never recognizing an eof. I included a simple fix, which I resend.
This bug persists to this day in g++ 2.95.
I would really appreciate some feedback. Perhaps you think there is a better
fix. I would love that. Perhaps there is a workaround. That is great, as I will
not have to apply the fix to a newer version.
Thanks, Joseph
Here is a small c++ program illustrating the bug.
-------------------------------------------------------
#include <stream.h>
#include <strstream.h>
int
main(int, char* [])
{
strstream s;
// How many lines? 4!!
s << "line 1\nline 2\n\nline 4";
s << ends;
int nLine = 0;
// This loop will never end
while( true ) {
char* line = 0;
s.gets(&line);
if( ! line ) {
break;
}
++nLine;
if( nLine > 10 ) {
cerr << "more than 10 lines" << endl;
exit(1);
}
}
return 0;
}
-------------------------------------------------------
The fix I found is: Still good for 2.95.
*** egcs-1.0.2/libio/strstream.cc Fri Aug 22 10:58:22 1997
--- egcs-980205/libio/strstream.cc Fri Feb 20 14:53:41 1998
***************
*** 68,74 ****
int strstreambuf::underflow()
{
! return _IO_str_underflow(this);
}
--- 68,79 ----
int strstreambuf::underflow()
{
! int c = _IO_str_underflow(this);
!
! if( c == EOF ) {
! _flags |= _IO_EOF_SEEN;
! }
! return c;
}