]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Don't possibly dereference a null pointer. 2962/head
authorDavid Wells <wellsd2@rpi.edu>
Sun, 14 Aug 2016 23:03:17 +0000 (19:03 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Mon, 15 Aug 2016 00:10:51 +0000 (20:10 -0400)
Since this code checks that the dimension really is not 1 we can get rid
of this case, which would result in an ill-formed reference.

source/grid/grid_out.cc

index f1d6f9b7890a105c20a89c0deaef34b8afe938c2..8918c6e5034ed25e921dd2c9996f65b3759fbf4f 100644 (file)
@@ -3552,17 +3552,17 @@ namespace internal
     {
       typedef std::list<LineEntry> LineList;
 
-      // get a pointer to the flags
-      // common to all dimensions, in
-      // order to avoid the recurring
-      // distinctions between
-      // eps_flags_1, eps_flags_2, ...
-      const GridOutFlags::EpsFlagsBase
-      &eps_flags_base = (dim==2 ?
-                         static_cast<const GridOutFlags::EpsFlagsBase &>(eps_flags_2) :
-                         (dim==3 ?
-                          static_cast<const GridOutFlags::EpsFlagsBase &>(eps_flags_3) :
-                          *static_cast<const GridOutFlags::EpsFlagsBase *>(0)));
+      // We should never get here in 1D since this function is overloaded for
+      // all dim == 1 cases.
+      Assert(dim == 2 || dim == 3, ExcInternalError());
+
+      // Copy, with an object slice, something containing the flags common to
+      // all dimensions in order to avoid the recurring distinctions between
+      // the different eps_flags present.
+      const GridOutFlags::EpsFlagsBase eps_flags_base =
+        dim == 2 ?
+        static_cast<const GridOutFlags::EpsFlagsBase &>(eps_flags_2) :
+        static_cast<const GridOutFlags::EpsFlagsBase &>(eps_flags_3);
 
       AssertThrow (out, ExcIO());
       const unsigned int n_points = eps_flags_base.n_boundary_face_points;

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.