]> https://gitweb.dealii.org/ - dealii.git/commitdiff
fix undefined behavior DynamicSparsityPatternIterators::Accessor::operator < 957/head
authorLei Qiao <qiaol618@gmail.com>
Sat, 23 May 2015 22:47:57 +0000 (17:47 -0500)
committerLei Qiao <qiaol618@gmail.com>
Sun, 24 May 2015 19:18:58 +0000 (14:18 -0500)
include/deal.II/lac/dynamic_sparsity_pattern.h

index 515b90fb530e9ec351c5c94e7f7c07e3ff3dc6ac..f52cc102c51a2637a9167dfb10a140d734955fb7 100644 (file)
@@ -757,16 +757,19 @@ namespace DynamicSparsityPatternIterators
     Assert (sparsity_pattern == other.sparsity_pattern,
             ExcInternalError());
 
-    // compare the sparsity pattern the iterator points into, properly
-    // taking into account the one-past-the-end iterator state
-    if ((current_row < sparsity_pattern->n_rows())
-        &&
-        (other.current_row == numbers::invalid_unsigned_int))
-      return true;
-    if ((other.current_row < other.sparsity_pattern->n_rows())
-        &&
-        (current_row == numbers::invalid_unsigned_int))
-      return false;
+    // if *this is past-the-end, then it is less than no one
+    if (current_row == numbers::invalid_unsigned_int)
+      return (false);
+    // now *this should be an valid value
+    Assert (current_row < sparsity_pattern->n_rows(),
+            ExcInternalError());
+
+    // if other is past-the-end
+    if (other.current_row == numbers::invalid_unsigned_int)
+      return (true);
+    // now other should be an valid value
+    Assert (other.current_row < sparsity_pattern->n_rows(),
+            ExcInternalError());
 
     // both iterators are not one-past-the-end
     return ((current_row < other.current_row) ||

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.