From 4f55421a9f40451c41f2a6e739de263aa7c96d5c Mon Sep 17 00:00:00 2001 From: bangerth Date: Tue, 15 Jan 2013 15:24:18 +0000 Subject: [PATCH] Avoid dereferencing the past-the-end iterator. git-svn-id: https://svn.dealii.org/trunk@28070 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/include/deal.II/lac/sparse_matrix.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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); } -- 2.39.5