From a915f0292ee8a4db2731638376ed0a55ca6930e4 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 28 Jun 2013 16:16:02 +0200 Subject: [PATCH] Fix bug #626: add assertion on input ranges for coeff* and insert members for sparse objects --- Eigen/src/SparseCore/SparseMatrix.h | 10 +++++++++- Eigen/src/SparseCore/SparseVector.h | 15 ++++++++++++--- test/sparse_basic.cpp | 4 ++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index fc6933a60..5a3918e2d 100644 --- a/Eigen/src/SparseCore/SparseMatrix.h +++ b/Eigen/src/SparseCore/SparseMatrix.h @@ -170,6 +170,8 @@ class SparseMatrix * This function returns Scalar(0) if the element is an explicit \em zero */ inline Scalar coeff(Index row, Index col) const { + eigen_assert(row>=0 && row=0 && col=0 && row=0 && col=0 && row=0 && col inline void reserveInnerVectors(const SizesType& reserveSizes) { - if(isCompressed()) { std::size_t totalReserveSize = 0; @@ -929,7 +934,10 @@ void set_from_triplets(const InputIterator& begin, const InputIterator& end, Spa VectorXi wi(trMat.outerSize()); wi.setZero(); for(InputIterator it(begin); it!=end; ++it) + { + eigen_assert(it->row()>=0 && it->row()col()>=0 && it->col()col() : it->row())++; + } // pass 2: insert all the elements into trMat trMat.reserve(wi); diff --git a/Eigen/src/SparseCore/SparseVector.h b/Eigen/src/SparseCore/SparseVector.h index d29a0977c..b05d409c3 100644 --- a/Eigen/src/SparseCore/SparseVector.h +++ b/Eigen/src/SparseCore/SparseVector.h @@ -83,14 +83,18 @@ class SparseVector inline Scalar coeff(Index row, Index col) const { - eigen_assert((IsColVector ? col : row)==0); + eigen_assert(IsColVector ? (col==0 && row>=0 && row=0 && col=0 && i=0 && row=0 && col=0 && i=0 && row=0 && col=0 && i void sparse_basic(const SparseMatrixType& re VERIFY_IS_APPROX(m.row(r) + m.row(r), refMat.row(r) + refMat.row(r)); } */ + + // test assertion + VERIFY_RAISES_ASSERT( m.coeffRef(-1,1) = 0 ); + VERIFY_RAISES_ASSERT( m.coeffRef(0,m.cols()) = 0 ); } // test insert (inner random)