This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

bug in strstream since Apr 1998



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;
  }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]