# HG changeset patch # User Rik # Date 1444520760 25200 # Node ID ffc6cdcd02c5dfb3b1c7d070e0e0c72ac4040248 # Parent 7890893a0e69752c867f0d325f68e9d11a6c26b1 Fix segfault when complex double matrix calls ZGETRF (bug #45577). * CMatrix.cc (finverse, determinant, rcond, fsolve): Calculate norm of matrix and if it is NaN, skip calling ZGETRF in LAPACK and set info to non-zero value to signal an error. diff -r 7890893a0e69 -r ffc6cdcd02c5 liboctave/array/CMatrix.cc --- a/liboctave/array/CMatrix.cc Thu Oct 08 20:59:25 2015 -0400 +++ b/liboctave/array/CMatrix.cc Sat Oct 10 16:46:00 2015 -0700 @@ -1131,11 +1131,14 @@ // Calculate the norm of the matrix, for later use. double anorm; - if (calc_cond) - anorm = retval.abs ().sum ().row (static_cast(0)) - .max (); - - F77_XFCN (zgetrf, ZGETRF, (nc, nc, tmp_data, nr, pipvt, info)); + //if (calc_cond) // Must always calculate anorm for bug #45577 + anorm = retval.abs ().sum ().row (static_cast(0)).max (); + + // Work around bug #45577, LAPACK crashes Octave if norm is NaN + if (xisnan (anorm)) + info = -1; + else + F77_XFCN (zgetrf, ZGETRF, (nc, nc, tmp_data, nr, pipvt, info)); // Throw-away extra info LAPACK gives so as to not change output. rcon = 0.0; @@ -1698,9 +1701,14 @@ // Calculate the norm of the matrix, for later use. double anorm = 0; - if (calc_cond) anorm = xnorm (*this, 1); - - F77_XFCN (zgetrf, ZGETRF, (nr, nr, tmp_data, nr, pipvt, info)); + //if (calc_cond) // Must always calculate anorm for bug #45577 + anorm = xnorm (*this, 1); + + // Work around bug #45577, LAPACK crashes Octave if norm is NaN + if (xisnan (anorm)) + info = -1; + else + F77_XFCN (zgetrf, ZGETRF, (nr, nr, tmp_data, nr, pipvt, info)); // Throw-away extra info LAPACK gives so as to not change output. rcon = 0.0; @@ -1891,7 +1899,11 @@ Array rz (dim_vector (2 * nc, 1)); double *prz = rz.fortran_vec (); - F77_XFCN (zgetrf, ZGETRF, (nr, nr, tmp_data, nr, pipvt, info)); + // Work around bug #45577, LAPACK crashes Octave if norm is NaN + if (xisnan (anorm)) + info = -1; + else + F77_XFCN (zgetrf, ZGETRF, (nr, nr, tmp_data, nr, pipvt, info)); if (info != 0) { @@ -2225,7 +2237,11 @@ anorm = atmp.abs ().sum ().row (static_cast(0)) .max (); - F77_XFCN (zgetrf, ZGETRF, (nr, nr, tmp_data, nr, pipvt, info)); + // Work around bug #45577, LAPACK crashes Octave if norm is NaN + if (xisnan (anorm)) + info = -2; + else + F77_XFCN (zgetrf, ZGETRF, (nr, nr, tmp_data, nr, pipvt, info)); // Throw-away extra info LAPACK gives so as to not change output. rcon = 0.0;