From: bangerth Date: Tue, 15 Jan 2013 15:24:18 +0000 (+0000) Subject: Avoid dereferencing the past-the-end iterator. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f55421a9f40451c41f2a6e739de263aa7c96d5c;p=dealii-svn.git Avoid dereferencing the past-the-end iterator. git-svn-id: https://svn.dealii.org/trunk@28070 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/lac/sparse_matrix.h b/deal.II/include/deal.II/lac/sparse_matrix.h index 0eaada198c..f006bc055e 100644 --- a/deal.II/include/deal.II/lac/sparse_matrix.h +++ b/deal.II/include/deal.II/lac/sparse_matrix.h @@ -2237,10 +2237,20 @@ namespace SparseMatrixIterators ExcInternalError()); const SparsityPattern &sparsity = accessor.get_matrix().get_sparsity_pattern(); + const unsigned int this_position - = sparsity.get_rowstart_indices()[(*this)->row()] + (*this)->index(); + = (*this != (*this)->get_matrix().end() + ? + sparsity.get_rowstart_indices()[(*this)->row()] + (*this)->index() + : + sparsity.get_rowstart_indices()[sparsity.n_rows()+1]); + const unsigned int other_position - = sparsity.get_rowstart_indices()[other->row()] + other->index(); + = (other != (*this)->get_matrix().end() + ? + sparsity.get_rowstart_indices()[other->row()] + other->index() + : + sparsity.get_rowstart_indices()[sparsity.n_rows()+1]); return (this_position - other_position); }