[SOLVED] Array of TVectorDs inside for loop cause crash

A few days ago I found strange behaviour of TVectorD objects. I have loop, inside I have declaration of TvectorD array of 128 elements. Loop executes excellent but problem comes after loop exit - program crashes without any reason. Removing this line causes that program executes correctly. Source of the program is attached.

Here is (end part of the) output of program:

[code]Warning in : Fit data is empty
Warning in : Fit data is empty
Warning in : Fit data is empty
+DEBUG: i = |30|
Warning in : Fit data is empty
Warning in : Fit data is empty
Warning in : Fit data is empty
+DEBUG: i = |31|

*** Break *** segmentation violation

===========================================================
There was a crash (#7 0x0108081c in SigHandler(ESignals) () from /opt/root/lib/libCore.so.5.27).
This is the entire stack trace of all threads:

#0 0x00e54422 in __kernel_vsyscall ()
#1 0x07d557d3 in __waitpid_nocancel () at …/sysdeps/unix/syscall-template.S:82
#2 0x07cf6de3 in do_system (line=) at …/sysdeps/posix/system.c:149
#3 0x05a9c27d in system (line=0x162557f8 “/opt/root/etc/gdb-backtrace.sh 4150 1>&2”) at pt-system.c:29
#4 0x0107920c in TUnixSystem::Exec(char const*) () from /opt/root/lib/libCore.so.5.27
#5 0x0107f461 in TUnixSystem::StackTrace() () from /opt/root/lib/libCore.so.5.27
#6 0x010806f3 in TUnixSystem::DispatchSignals(ESignals) () from /opt/root/lib/libCore.so.5.27
#7 0x0108081c in SigHandler(ESignals) () from /opt/root/lib/libCore.so.5.27
#8 0x010765e0 in sighandler(int) () from /opt/root/lib/libCore.so.5.27
#9
#10 0x0804fe7d in scurve_calib (filename=…, xlow=100, xhigh=180) at /home/rlalik/src/tumsetup-0.6/scurve_calib.cxx:40
#11 0x08050583 in main (argc=1, argv=0xbfafda64) at /home/rlalik/src/tumsetup-0.6/scurve_calib.cxx:145

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#10 0x0804fe7d in scurve_calib (filename=…, xlow=100, xhigh=180) at /home/rlalik/src/tumsetup-0.6/scurve_calib.cxx:40
#11 0x08050583 in main (argc=1, argv=0xbfafda64) at /home/rlalik/src/tumsetup-0.6/scurve_calib.cxx:145
===========================================================[/code]

and here is output of gdb:

[code]Warning in : Fit data is empty
Warning in : Fit data is empty
Warning in : Fit data is empty
+DEBUG: i = |30|
Warning in : Fit data is empty
Warning in : Fit data is empty
Warning in : Fit data is empty
+DEBUG: i = |31|

Program received signal SIGSEGV, Segmentation fault.
0x0804fe7d in scurve_calib (filename=…, xlow=100, xhigh=180) at /home/rlalik/src/tumsetup-0.6/scurve_calib.cxx:40
40 TVectorD min[128];
(gdb)[/code]

However this array is not used anymore because is a port of the old design, but problem exists and is very confusing for me.

Here is also another problem with declaration of array of doubles but it is to much for this topic, I will open one more.
scurve_calib.cxx (3.15 KB)

Are you getting this problem with CINT or compiled code?
Could you post your data file such that we can investigate?

Rene

Thanks Rene, you solved my problem :slight_smile:

When you ask whether it works in interpreted mode (till now I was running it in g++ and ACLic mode), Cint shown “array index out of range”. In fact, declaration of array in line #38 has second dimension to low: 0x1f instead of 0x20. After this fix everything works fine, also problem from this topic: [SOLVED] Strange behavior of array of doubles

Explanation is easy, when program writes to last three elements of array it overwrites some memory owned by TVectorD array, and after this program crash, when destructor for TVectorD is call.

The same was for array of doubles. Now I found that corrupted values found in first three elements of array match to values from fitting (stored in another array with index out of range).

Thanks again and all the best,
Rafal

To moderator: Please remove this post, created by mistake