From c9369a4dff94c60e12ee83a80974c625f680da66 Mon Sep 17 00:00:00 2001 From: Lei Qiao Date: Sat, 23 May 2015 17:47:57 -0500 Subject: [PATCH] fix undefined behavior DynamicSparsityPatternIterators::Accessor::operator < --- .../deal.II/lac/dynamic_sparsity_pattern.h | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/include/deal.II/lac/dynamic_sparsity_pattern.h b/include/deal.II/lac/dynamic_sparsity_pattern.h index 515b90fb53..f52cc102c5 100644 --- a/include/deal.II/lac/dynamic_sparsity_pattern.h +++ b/include/deal.II/lac/dynamic_sparsity_pattern.h @@ -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) || -- 2.39.5