From: Lei Qiao Date: Sat, 23 May 2015 22:47:57 +0000 (-0500) Subject: fix undefined behavior DynamicSparsityPatternIterators::Accessor::operator < X-Git-Tag: v8.3.0-rc1~153^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F957%2Fhead;p=dealii.git fix undefined behavior DynamicSparsityPatternIterators::Accessor::operator < --- 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) ||