From 27ac7a577240d0769fb6a0ced4a35377bafae70f Mon Sep 17 00:00:00 2001 From: David Wells Date: Tue, 18 Jul 2017 12:22:21 -0400 Subject: [PATCH] Add an extra iterator validation check. Coverity complains about this, so we may as well add an extra check for iterator correctness. --- source/numerics/time_dependent.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/numerics/time_dependent.cc b/source/numerics/time_dependent.cc index 257cf0bbe3..bee615228c 100644 --- a/source/numerics/time_dependent.cc +++ b/source/numerics/time_dependent.cc @@ -97,14 +97,18 @@ TimeDependent::insert_timestep (const TimeStepBase *position, else { // inner time step - std::vector >::iterator insert_position + const std::vector >::iterator insert_position = std::find(timesteps.begin(), timesteps.end(), position); + // check iterators again to satisfy coverity: both insert_position and + // insert_position - 1 must be valid iterators + Assert(insert_position != timesteps.begin() && + insert_position != timesteps.end(), ExcInternalError()); (*(insert_position-1))->set_next_timestep (new_timestep); new_timestep->set_previous_timestep (*(insert_position-1)); new_timestep->set_next_timestep (*insert_position); (*insert_position)->set_previous_timestep (new_timestep); - }; + } // finally enter it into the // array -- 2.39.5