From 5cb3177f608b684c8e4c28bbae63138b5ce8a108 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 24 Oct 2017 18:05:10 -0600 Subject: [PATCH] Add a check when comparing iterators. Right now, comparing iterators only compares their level and index, but surprisingly not the triangulation pointers. There is an assertion higher up that makes sure that if the triangulation pointers of both objects are both non-nullptr, that they are the same, but it is conceivable that one of the objects in invalid and the other has a valid pointer. Internally, if that is the case, we have the invariant that for iterators for which the triangulation pointer is nullptr, that the level and index values are also invalid, and so nothing bad can happen (TM) with the current code. But it still seems prudent to also compare triangulation pointers, even if we know that if one only of the pointers is nullptr, then the other comparisons for equality must necessarily also fail because of the invariant -- we should just err on the side of safety. I've thought whether the pointers should be compared first or last. I put it first because I think that the common case is to compare 'cell != endc', and in that case one has a valid pointer and the other does not, so the first check will already fail. --- include/deal.II/grid/tria_accessor.templates.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/deal.II/grid/tria_accessor.templates.h b/include/deal.II/grid/tria_accessor.templates.h index 48f187b00c..da38181ba7 100644 --- a/include/deal.II/grid/tria_accessor.templates.h +++ b/include/deal.II/grid/tria_accessor.templates.h @@ -120,7 +120,8 @@ TriaAccessorBase::operator == (const TriaAccessorBase::operator != (const TriaAccessorBase