Hello,
When asked to perform a matrix operation that results in an overly large matrix, TMatrixT segfaults (*). I’d like to suggest a patch that identifies the overflow and raises the appropriate error. Given that other error conditions are checked in a similar manner in this method, I hope the speed vs. usability trade off is acceptable to the ROOT developers.
The patch is for root/math/matrix/src and for ROOT v5.34/32 goes like:
[code]492a493,498
if( ((Long64_t)this->fNrows)*this->fNcols != this->fNelems )
{
Error(“Allocate”,“too large: no_rows=%d no_cols=%d”,no_rows,no_cols);
this->Invalidate();
return;
}
[/code]
With it, instead of a segfault you can get:
root [0] TMatrixD m( 80000, 80000 )
Error in <Allocate>: too large: no_rows=80000 no_cols=80000
(*) more precisely, if the result of signed integer overflow are undefined (I’m pretty sure that’s the case in C, not sure about the various C++ standards), whether the code segfaults or not depends on what value is stored in fNelems after the overflow. On my x86_64 linux box, with gcc 4.9.3, I get segfaults.
cheers,
Amnon Harel