]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add an extra iterator validation check. 4626/head
authorDavid Wells <wellsd2@rpi.edu>
Tue, 18 Jul 2017 16:22:21 +0000 (12:22 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Tue, 18 Jul 2017 16:22:21 +0000 (12:22 -0400)
Coverity complains about this, so we may as well add an extra check for
iterator correctness.

source/numerics/time_dependent.cc

index 257cf0bbe389d2b7605b55ed1ffd9f45ad92564a..bee615228c57779f57025c10bb5be64d06d72ea9 100644 (file)
@@ -97,14 +97,18 @@ TimeDependent::insert_timestep (const TimeStepBase *position,
   else
     {
       // inner time step
-      std::vector<SmartPointer<TimeStepBase,TimeDependent> >::iterator insert_position
+      const std::vector<SmartPointer<TimeStepBase,TimeDependent> >::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

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.