]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Avoid creating pointer to invalid memory in get_dof_indices 6413/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Tue, 1 May 2018 09:58:32 +0000 (11:58 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Tue, 1 May 2018 10:10:39 +0000 (12:10 +0200)
include/deal.II/dofs/dof_accessor.templates.h
include/deal.II/dofs/dof_levels.h

index 5aa4c4fc18c4a8a8a229ef3fc1b48d34a37d19f3..0ce19502a854729148ca638aa96e38dd36788764 100644 (file)
@@ -3459,11 +3459,15 @@ DoFCellAccessor<DoFHandlerType,level_dof_access>::get_dof_indices
           ExcMessage ("Can't ask for DoF indices on artificial cells."));
   AssertDimension (dof_indices.size(), this->get_fe().dofs_per_cell);
 
-  const types::global_dof_index *cache
-    = this->dof_handler->levels[this->present_level]
-      ->get_cell_cache_start (this->present_index, this->get_fe().dofs_per_cell);
-  for (unsigned int i=0; i<this->get_fe().dofs_per_cell; ++i, ++cache)
-    dof_indices[i] = *cache;
+  const auto dofs_per_cell = this->get_fe().dofs_per_cell;
+  if (dofs_per_cell > 0)
+    {
+      const types::global_dof_index *cache
+        = this->dof_handler->levels[this->present_level]
+          ->get_cell_cache_start (this->present_index, dofs_per_cell);
+      for (unsigned int i=0; i<dofs_per_cell; ++i, ++cache)
+        dof_indices[i] = *cache;
+    }
 }
 
 
index b1562b29ce0d067366940aa9a08837163ad02c9a..21983b137ac19370faed88c0b066377321b44aa8 100644 (file)
@@ -122,7 +122,7 @@ namespace internal
               cell_dof_indices_cache.size(),
               ExcInternalError());
 
-      return &cell_dof_indices_cache[obj_index*dofs_per_cell];
+      return cell_dof_indices_cache.data()+(obj_index*dofs_per_cell);
     }
 
 

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.