Pointer to TMatrix, row index out of bound

Hi ROOTers,

I am experincing the following issue. I have to fill the elements of a TMatrixDSym.
If I use the [] operator to fill the matrix, and the object is declared as a pointer to TMatrixDSym, I get a seg violation error.
This does not happen if the object is declared as TMatrixDSym (no pointer).

Also, I experience no problem if I fill the matrix using the SetMatrixArray method, in both cases. This points to some issue in the definition of the [] operator.
Or, maybe, I am just filling the matrix the wrong way :slight_smile:

Attached is a minimal example. There are two #define directives to set/unset the the way TMatrixDSym is declared, and the way it is filled.

The combination
#define POINTER
//#define SETMATARR
makes the code crash. The other 3 combinations do not.

My ROOT version is 5.34/04

Thanks for checking and for any suggestion!

Byez,

Valerio
minimal_example.C (739 Bytes)

Hi Valerio,

this is a C++ related issue. If you use the “non-pointer” solution, you are invoking the overloaded operator[]: root.cern.ch/root/html/TMatrixT … _:operator[]
In the case of the “pointer” the procedure is bogus. You are treating the TMatrix pointer as a C array and accessing a random memory location.

Cheers,
Danilo