]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Avoid dereferencing the past-the-end iterator.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 15 Jan 2013 15:24:18 +0000 (15:24 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 15 Jan 2013 15:24:18 +0000 (15:24 +0000)
git-svn-id: https://svn.dealii.org/trunk@28070 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/lac/sparse_matrix.h

index 0eaada198cd4c27aaff0272a5f62c6dae28a0c7e..f006bc055e2a2f90d8e0d494b992dfc04694e27c 100644 (file)
@@ -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);
   }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.