]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Avoid iterator past end
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 22 Apr 2003 07:40:45 +0000 (07:40 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 22 Apr 2003 07:40:45 +0000 (07:40 +0000)
git-svn-id: https://svn.dealii.org/trunk@7442 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/sparse_matrix_ez.h

index 18d8b92580f7116594ea365ad7143f28926f5b19..f9f286cbfac666ffd663494ac49e4340125497b8 100644 (file)
@@ -1474,11 +1474,21 @@ SparseMatrixEZ<number>::begin (const unsigned int r) const
 template <typename number>
 inline
 typename SparseMatrixEZ<number>::const_iterator
-SparseMatrixEZ<number>::end (const unsigned int r) const
+SparseMatrixEZ<number>::end (unsigned int r) const
 {
   Assert (r<m(), ExcIndexRange(r,0,m()));
-  const_iterator result(this, r+1, 0);
-  if (row_info[r+1].length == 0)
+
+                                  // Usually, we should return the
+                                  // first element of the next row.
+  const_iterator result(this, ++r, 0);
+
+                                  // If r was the last row, this is
+                                  // always true. Otherwise, we have
+                                  // to make sure that there IS an
+                                  // entry in the next row. If not,
+                                  // we advance to the next valid
+                                  // entry or end().
+  if (r < row_info.size() && row_info[r].length == 0)
     ++result;
   return result;
 }

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.