Mercurial > octave
changeset 22044:571b42508e1e
Avoid segfault with matrices containing Inf & NaN (bug #46330).
* liboctave/array/CMatrix.cc (ComplexMatrix::finverse): check for Inf.
* liboctave/array/CMatrix.cc (ComplexMatrix::fsolve): check for Inf, return
appropriate value.
author | Lachlan Andrew <lachlanbis@gmail.com> |
---|---|
date | Wed, 06 Jul 2016 14:49:00 +0200 |
parents | 7d28674f6ff0 |
children | d3c79eb1b483 |
files | liboctave/array/CMatrix.cc |
diffstat | 1 files changed, 10 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/array/CMatrix.cc Tue Jul 05 15:53:35 2016 -0700 +++ b/liboctave/array/CMatrix.cc Wed Jul 06 14:49:00 2016 +0200 @@ -1049,7 +1049,8 @@ anorm = retval.abs ().sum ().row (static_cast<octave_idx_type>(0)).max (); // Work around bug #45577, LAPACK crashes Octave if norm is NaN - if (octave::math::isnan (anorm)) + // and bug #46330, segfault with matrices containing Inf & NaN + if (octave::math::isnan (anorm) || octave::math::isinf (anorm)) info = -1; else F77_XFCN (zgetrf, ZGETRF, (nc, nc, tmp_data, nr, pipvt, info)); @@ -1074,7 +1075,7 @@ info = -1; } - if (info == -1 && ! force) + if ((info == -1 && ! force) || octave::math::isinf (anorm)) retval = *this; // Restore contents. else { @@ -2138,7 +2139,8 @@ .max (); // Work around bug #45577, LAPACK crashes Octave if norm is NaN - if (octave::math::isnan (anorm)) + // and bug #46330, segfault with matrices containing Inf & NaN + if (octave::math::isnan (anorm) || octave::math::isinf (anorm)) info = -2; else F77_XFCN (zgetrf, ZGETRF, (nr, nr, tmp_data, nr, pipvt, info)); @@ -2201,6 +2203,11 @@ mattype.mark_as_rectangular (); } } + if (octave::math::isinf (anorm)) + { + retval = ComplexMatrix (b.rows (), b.cols (), Complex (0, 0)); + mattype.mark_as_full (); + } } return retval;