Re: [ROOT] Segmentation fault in loop with mask

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Apr 08 2002 - 23:15:12 MEST


Hi Ranpal,

This is unfortunately a CINT problem when an object is created
inside an if block, itself in a loop.
The solution is to change your code as shown below.
I hope that Masa will fix this problem in a coming version of CINT.

Rene Brun

On Mon, 8 Apr 2002, Ranpal Singh Dosanjh wrote:

> Dear rooters,
> 
> I have a bizarre segmentation fault which I am trying to understand, and 
> I hope someone can help me.  I've reduced the problem to the following
> macro:
> 
> {
>   gROOT->Reset();
> 
>   Int_t i=1;
>   Int_t n = 3;
>   Int_t mask[n]={0,0,1};
> 
  TString hello;

>   for (i=0;i<n;i++) {
>       if (mask[i]) {
>               hello = "hello";
>               cout << hello << endl;
>       } 
>   }
> 
> }
> 
> This results in a segmentation fault.  However, if mask is, say, {1,0,1},
> then there is no segmentation fault, and the macro behaves as expected. 
> In fact, the only configuration of mask elements for which a segmentation
> fault occurs is zero in the first element and at least one non-zero
> element. 
> 
> I'm running root 3.02/07 on Linux, if it makes a difference.
> 
> Thanks,
> 
> Ranpal
> 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:48 MET