🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #110

Libg++2.0 iostream overflow() crashes -- a workaround

#110
From: Lawrence Fried
Date: Tue, 07 Apr 1992 05:53
55 lines
2809 bytes
	I experienced a problem with libg++2.0 compiled under GCC 2.0 
on an SGI 4-D system running Irix 4.0.1. 
filebuf::overflow(int) would go into an infinite recursive loop.
This problem would occur unpredictably in programs that did a moderate
amount of output (over 100 lines) to cout or cerr.  After a lot of poking
around, I noticed that do_flush() in filebuf.C would change the status of
the output stream from is_reading() == 0 to is_reading() == 1.  Since that
seemed illogical, I changed do_flush() so that it doesn't modify the 
is_reading() status.  I had 5 or 6 programs that crashed at various points; 
all the crashes went away after making this change.  Also, libg++ compiled with
this patch passed the I/O tests supplied with libg++.

	Since I don't fully understand the iostream code, I would use the
below patch with caution.  If you're experiencing nasty iostream
crashes, try the patch (you're probably desperate anyway). 

	To the developers of libg++ :: The new iostream is great. It
adds important functionality to the old stream class.  
HOWEVER, its maddening to use an I/O utility in all of your programs 
that crashes a lot.  Could you supply an "official" patch to the 
overflow() problem ?  This problem is too serious to wait a few months for 
the next version of libg++.

	Another note:  I found that cout was not always flushed after the
program finished (with or without my patch).  A quick fix that I used was 
to set the flag ios::unitbuf in the definition of cout.  
Does anybody else have a better fix ?

*** filebuf.C.old	Tue Apr  7 01:14:38 1992
--- filebuf.C	Fri Apr  3 00:41:12 1992
***************
*** 388,394 ****
  	to_do -= count;
  	ptr += count;
      }
!     setg(base(), pptr(), pptr());	
      setp(base(), base());
      return 0;
  }
--- 388,398 ----
  	to_do -= count;
  	ptr += count;
      }
!     if ( is_reading() ) {
! 	 setg(base(), pptr(), pptr());
!     } else {  // All pointers should be equal in put mode (LEF) 
! 	 setg(base(), base(), base() ) ;
!     }
      setp(base(), base());
      return 0;
  }

-------------------------------------------------------------------------------
	Larry Fried (larry@liouville.chem.rochester.edu)
	University of Rochester
Technical Details
Message-ID: <1992Apr7.055314.24558@galileo.cc.rochester.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!uhura.cc.rochester.edu!laf4
References: <memo.362196@cix.compulink.co.uk>

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!uhura.cc.rochester.edu!laf4
From: laf4@uhura.cc.rochester.edu (Lawrence Fried)
Subject: Libg++2.0 iostream overflow() crashes -- a workaround
Message-ID: <1992Apr7.055314.24558@galileo.cc.rochester.edu>
Keywords: libg++2.0 iostream
Sender: gnulists@ai.mit.edu
Organization: University of Rochester (Rochester, NY)
References: <memo.362196@cix.compulink.co.uk>
Distribution: gnu
Date: Tue, 7 Apr 1992 05:53:14 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 56