[ROOT] 2.24.05: bug in TMap and TObjArray

From: Matthew D. Langston (langston@SLAC.stanford.edu)
Date: Sun May 28 2000 - 23:41:13 MEST


There is a bug in TMap and TObjArray in ROOT 2.24.05.  I can't be any
more specific that this, because the error message printed by ROOT is
meaningless (i.e. the ubiquitous "segmentation violation" message).

I have, however, attached a file named CollectionBug.cxx which
reproduces the bug.  The bug is only present when CollectionBug.cxx is
interpreted by ROOT.  It runs fine when compiled.

Here is the output from ROOT:

  root [0] .L CollectionBug.cxx
  root [1] CollectionBug bug;
  root [2] bug.Print();
  baz
  foo
  bar
  
   *** Break *** segmentation violation
  Root > Function Print() busy flag cleared


Regards, Matt

 
--
Matthew D. Langston
SLD, Stanford Linear Accelerator Center
langston@SLAC.Stanford.EDU

#ifndef __CINT__
#include <TObjString.h>
#include <TObjArray.h>
#include <TMap.h>
#include <iostream>
#endif


class CollectionBug
{
   public:

      CollectionBug();
      
      void Print();

   private:

      TMap*  fMap;
};


#ifndef __CINT__
int
main( int argc, char* argv[] )
{
   CollectionBug bug;
   bug.Print();
}
#endif


CollectionBug::CollectionBug()
{
   fMap = new TMap();
   TObjArray* files;

   files = new TObjArray();   
   files->Add( new TObjString( "1" ) );
   fMap->Add( new TObjString( "foo" ), files );

   files = new TObjArray();   
   files->Add( new TObjString( "1" ) );
   fMap->Add( new TObjString( "bar" ), files );

   files = new TObjArray();   
   files->Add( new TObjString( "1" ) );
   fMap->Add( new TObjString( "baz" ), files );
}
      

void
CollectionBug::Print()
{
   TObjString* name;
   TIter next_dataset( fMap );
   while ( ( name = dynamic_cast< TObjString* >( next_dataset() ) ) != 0 )
   {
      cout << name->String() << endl;
      TObjArray* files = dynamic_cast< TObjArray* >( fMap->GetValue( name ) );
      TIter next_file( files );
   }
}


// Local variables:
//  compile-command: "g++ `root-config --cflags --libs` -Wl,-rpath,$ROOTSYS/lib -Wall CollectionBug.cxx -o CollectionBug"
// End:



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:26 MET