Re: [ROOT] ostrstream and TApplication

From: Andre Holzner (Andre.Holzner@cern.ch)
Date: Thu May 17 2001 - 21:18:44 MEST


Mike Kordosky wrote:
> 
> 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.

yes... I tried e.g. (not linking against root): 

#include <iostream>
#include <strstream>
 
void main()
{
  {
    ostrstream foo;
    foo << "bar this should not be visible";
  }
 
  ostrstream foo2;
 
  foo2 << "bar";
 
  cout << foo2.str() << endl;
 
}

which should print 
  bar

but instead prints

  bar this should not be visible

i.e. foo2 contains bar, however, the memory does not contain
the ending \0, i.e. foo2.str() continues to read up to the next
\0. Accidentally, the memory used by the variable foo (which is
not visible any more where foo2 is declared) is the same
as the one used by foo2, that is why there is a \0.

I haven't followed the libNew story, but maybe the different
behaviour of the different root versions is related to this 
(i.e. not everything is initialized to 0 automatically) ?


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