fix bug #410: fix a possible out of range access in EigenSolver

This commit is contained in:
Gael Guennebaud 2012-01-25 19:02:31 +01:00
parent 362fcabc44
commit a108216af1
2 changed files with 12 additions and 1 deletions

View File

@ -339,7 +339,7 @@ typename EigenSolver<MatrixType>::EigenvectorsType EigenSolver<MatrixType>::eige
EigenvectorsType matV(n,n);
for (Index j=0; j<n; ++j)
{
if (internal::isMuchSmallerThan(internal::imag(m_eivalues.coeff(j)), internal::real(m_eivalues.coeff(j))))
if (internal::isMuchSmallerThan(internal::imag(m_eivalues.coeff(j)), internal::real(m_eivalues.coeff(j))) || j+1==n)
{
// we have a real eigen value
matV.col(j) = m_eivec.col(j).template cast<ComplexScalar>();

View File

@ -114,6 +114,17 @@ void test_eigensolver_generic()
// Test problem size constructors
CALL_SUBTEST_5(EigenSolver<MatrixXf>(s));
// regression test for bug 410
CALL_SUBTEST_2(
{
MatrixXd A(1,1);
A(0,0) = std::sqrt(-1.);
Eigen::EigenSolver<MatrixXd> solver(A);
MatrixXd V(1, 1);
V(0,0) = solver.eigenvectors()(0,0).real();
}
);
EIGEN_UNUSED_VARIABLE(s)
}