Re: [ROOT] ostrstream and TApplication

From: Mike Kordosky (kordosky@mail.hep.utexas.edu)
Date: Thu May 17 2001 - 19:29:13 MEST


Hi Andre & rooters, 

I actually knew that terminating with '\0' solved the
problem, but I wasn't sure if that was a symptom of the problem or the
true blue solution. So we have just been lucky about not terminating
ostrstreams?  I found this bug especially hard to understand since we can
get away without terminating ostrstreams when linking with earlier
versions of the ROOT libraries (v2.32.12 for example).  Such is the nature
of these sort of bugs, I suppose.

By the way, does anyone know if there is a gnu implementation of
stringstreams?  I sniffed around a bit and it looked like there would not
be an official implementation until gcc-v3 comes out, but I could be
wrong.  Does anyone have an implementation that they know works correctly
with egcs-2.91.66?

Thanks,

Mike Kordosky

///////////////////////////////////////////////////////////////////  
// Graduate Research Assistant  //  High Energy Physics          //
// RLM Office: (512) 471-8426  //  University of Texas, Austin   //
// RLM Lab: (512) 471-3526    //  kordosky@hep.utexas.edu        //
// ENS Lab: (512) 475-8673   //  kordosky@fnal.gov               //
///////////////////////////////////////////////////////////////////

On Thu, 17 May 2001, Andre Holzner wrote:

> Hi Mike,
> > 
> > Hi,
> > 
> > Could someone explain the following behaviour to me?
> > 
> > #include <strstream>
> > #include <iostream>
> > #include "TROOT.h"
> > #include "TApplication.h"
> > 
> > TROOT rsession("test", "test");
> > 
> > main(int argc, char** argv)
> > {
> > //      TApplication app("App", &argc, argv);
> >         ostrstream buf;
> >         buf<< "hello";
> 
> you should do
> 
>   buf << "hello" << '\0';
> 
> to be safe. At least the GNU libg++ library says that
> you should (from info iostream):
> 
>  - Method: char* ostrstream::str ()
>      A pointer to the string managed by this `ostrstream'.  Implies
>      `ostrstream::freeze()'.
>  
>      Note that if you want the string to be nul-terminated, you must do
>      that yourself (perhaps by writing ends to the stream).
> 
> So it's gnu libg++ related, not CINT (I don't know whether
> I posted the small example which tries to reuse the same
> memory for two variables to demonstrate that the string
> is only accidentally null-terminated if you don't write
> a '\0' af the end).
> 
> 
> best regards,
> 
> André
> 
> 
> -- 
> ------------------+----------------------------------
> Andre Holzner     | +41 22 76 76750 
> Bureau 32 2-C13   | Building 32     
> CERN              | Office 2-C13    
> CH-1211 Geneve 23 | http://wwweth.cern.ch/~holzner/
> 



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:45 MET