Unexpected segmentation violation

Hi,
I am reading an ascii file, create and fill a tree and perform analysis and I have the following segmentation violation.

The script sometimes works sometimes not.
The function read() works fine, it is plot() that generate segmentation violation.

Thank you,
Anton

I am using fedora 5 on amd 64, gcc 4.1.1

ROOT 5.25/02 (trunk@30530, Sep 29 2009, 15:28:19 on linuxx8664gcc)

CINT/ROOT C/C++ Interpreter version 5.17.00, Dec 21, 2008
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0]
Processing chrom3.C…

*** Break *** segmentation violation
#0 0x0000003fd14934b5 in waitpid () from /lib64/libc.so.6
#1 0x0000003fd143aff3 in do_system () from /lib64/libc.so.6
#2 0x00002aaaaad2e577 in TUnixSystem::StackTrace ()
#3 0x00002aaaaad2ba7a in TUnixSystem::DispatchSignals ()
#4
#5 0x00002aaaab58f9a8 in G__isfriend () from /usr/local/root/lib/libCint.so
#6 0x00002aaaab4cbf66 in G__interpret_func ()
#7 0x00002aaaab4b9803 in G__getfunction () from /usr/local/root/lib/libCint.so
#8 0x00002aaaab5a72d0 in G__getstructmem ()
#9 0x00002aaaab59c879 in G__getvariable () from /usr/local/root/lib/libCint.so
#10 0x00002aaaab48f39c in G__getitem () from /usr/local/root/lib/libCint.so
#11 0x00002aaaab49a400 in G__getexpr () from /usr/local/root/lib/libCint.so
#12 0x00002aaaab523051 in G__exec_statement ()
#13 0x00002aaaab4cdfdf in G__interpret_func ()
#14 0x00002aaaab4b996f in G__getfunction () from /usr/local/root/lib/libCint.so
#15 0x00002aaaab48f504 in G__getitem () from /usr/local/root/lib/libCint.so
#16 0x00002aaaab49a400 in G__getexpr () from /usr/local/root/lib/libCint.so
#17 0x00002aaaab523051 in G__exec_statement ()
#18 0x00002aaaab4cdfdf in G__interpret_func ()
#19 0x00002aaaab4b996f in G__getfunction () from /usr/local/root/lib/libCint.so
#20 0x00002aaaab48f504 in G__getitem () from /usr/local/root/lib/libCint.so
#21 0x00002aaaab49a400 in G__getexpr () from /usr/local/root/lib/libCint.so
#22 0x00002aaaab4a1a30 in G__calc_internal ()
#23 0x00002aaaab52cba8 in G__process_cmd () from /usr/local/root/lib/libCint.so
#24 0x00002aaaaad178c7 in TCint::ProcessLine ()
#25 0x00002aaaaad1c933 in TCint::ProcessLineSynch ()
#26 0x00002aaaaac57dd4 in TApplication::ExecuteFile ()
#27 0x00002aaaaac55d4b in TApplication::ProcessLine ()
#28 0x00002aaaabfa561b in TRint::Run () from /usr/local/root/lib/libRint.so
#29 0x000000000040104d in main ()
Root > Function plot() busy flag cleared
Function chrom3() busy flag cleared
.q
chrom3.C (3.75 KB)

you forgot to post your data file

Rene

I am sorry.

I had to change extension for data file, so use this script and this data file.

Anton
chrom3.C (3.73 KB)
ctau-SIR.txt (51 KB)

I cannot reproduce your problem.
Could you run under gdb

gdb root.exe and report the reslut of

gdb > bt when your program crashes

Rene

Hi,

I can see the problem in #8 0x00007faf6578a178 in TRefCnt::RemoveReference (this=0x402f79c13046d0a4) at include/TRefCnt.h:43 #9 0x00007faf657a5f6e in TStringRef::UnLink (this=0x402f79c13046d0a4) at include/TString.h:425 #10 0x00007faf657a12d8 in ~TString (this=0x7fff770a6650, __in_chrg=<value optimized out>) at core/base/src/TString.cxx:371 #11 0x00007faf5fe9b954 in TTreePlayer::Scan (this=0x283a110, varexp=0x7faf62665922 "name:S:MUX:K1L*BETX", selection=0x27c4928 "(K1L*BETX) <-30 || (K1L*BETX) >30", option=0x7faf62665917 "colsize=11", nentries=30, firstentry=0) at tree/treeplayer/src/TTreePlayer.cxx:3256 #12 0x00007faf61933c5a in TTree::Scan (this=0x27aa6a0, varexp=0x7faf62665922 "name:S:MUX:K1L*BETX", selection=0x27c4928 "(K1L*BETX) <-30 || (K1L*BETX) >30", option=0x7faf62665917 "colsize=11", nentries=1000000000, firstentry=0) at tree/tree/src/TTree.cxx:5811 #13 0x00007faf62662fdf in plot () at /home/axel/Desktop/./chrom3.C:84 #14 0x00007faf6266386a in chrom3 () at /home/axel/Desktop/./chrom3.C:133
in the attached version of the script, when compiling with ACLiC. I’ve told Philippe who will look into it.

Cheers, Axel.
chrom3.C (4.16 KB)

Rene,

I added “tree->Show(0)” to read() function and attached file with what gdb gives. The script is included.
gdb-output.txt (8.29 KB)
chrom3.C (3.73 KB)

Hi,

For completeness sake. There was two issue with the original user code: name_str.copy(name,name_str.size());does not terminate the copied string with a null character which is required to make it a proper c-style string. Using: name_str.copy(name,name_str.size()); name[name_str.size()] = '\0';fixes the problem.

The code also does [code]void read(){

optic_t entry1,entry2,entry3;
Char_t name[17];

TTree *tree=new TTree(“tree”,“optics data”);
tree->Branch(“optics”,&entry2.S,“S/D:BETX/D:BETY:MUX:MUY:DX:DPX:DDX:DDPX:WX:WY:PHIX:PHIY:K1L:K2L”);
tree->Branch(“elements”,name,“name/C”);
…}[/code]which means that at the end of this function the TTree object still exist but point to memory (the name, entry1, etc) that is no longer valid. Call tree->ResetBranchAddresses();to resolve the problem.

Cheers,
Philippe.