]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Null pointer check added to CellDagaStorage::get_data()
authorReza Rastak <rastak@stanford.edu>
Tue, 6 Aug 2019 20:58:58 +0000 (14:58 -0600)
committerReza Rastak <rastak@stanford.edu>
Tue, 6 Aug 2019 20:58:58 +0000 (14:58 -0600)
include/deal.II/base/quadrature_point_data.h

index 154ce61bf000e127353cdcd9d211063770a085bb..8656eac4015b3464b3d77a01b30bc843d071d520 100644 (file)
@@ -163,6 +163,13 @@ private:
    * A map to store a vector of data on a cell.
    */
   std::map<CellIteratorType, std::vector<std::shared_ptr<DataType>>> map;
+
+  /**
+   * @addtogroup Exceptions
+   */
+  DeclExceptionMsg(
+    ExcCellDataTypeMismatch,
+    "Cell data is being retrieved with a type which is different than the type used to initialize it");
 };
 
 
@@ -617,7 +624,10 @@ CellDataStorage<CellIteratorType, DataType>::get_data(
   // the T==DataType:
   std::vector<std::shared_ptr<T>> res(it->second.size());
   for (unsigned int q = 0; q < res.size(); q++)
-    res[q] = std::dynamic_pointer_cast<T>(it->second[q]);
+    {
+      res[q] = std::dynamic_pointer_cast<T>(it->second[q]);
+      Assert(res[q], ExcCellDataTypeMismatch());
+    }
   return res;
 }
 
@@ -640,7 +650,10 @@ CellDataStorage<CellIteratorType, DataType>::get_data(
   // does not modify the content of QP objects
   std::vector<std::shared_ptr<const T>> res(it->second.size());
   for (unsigned int q = 0; q < res.size(); q++)
-    res[q] = std::dynamic_pointer_cast<const T>(it->second[q]);
+    {
+      res[q] = std::dynamic_pointer_cast<const T>(it->second[q]);
+      Assert(res[q], ExcCellDataTypeMismatch());
+    }
   return res;
 }
 

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.