]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix serialization of possibly empty SparsityPattern objects.
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 7 Jan 2022 07:19:41 +0000 (00:19 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 7 Jan 2022 07:19:41 +0000 (00:19 -0700)
include/deal.II/lac/sparsity_pattern.h

index 011acc1acbabc5b56326f6f184db70487c06eb47..0306c6ac89b479d651b67502b92c7dca0bbffe01 100644 (file)
@@ -1588,8 +1588,15 @@ SparsityPatternBase::save(Archive &ar, const unsigned int) const
 
   ar &max_dim &rows &cols &max_vec_len &max_row_length &compressed;
 
-  ar &boost::serialization::make_array(rowstart.get(), max_dim + 1);
-  ar &boost::serialization::make_array(colnums.get(), max_vec_len);
+  if (max_dim != 0)
+    ar &boost::serialization::make_array(rowstart.get(), max_dim + 1);
+  else
+    Assert(rowstart.get() == nullptr, ExcInternalError());
+
+  if (max_vec_len != 0)
+    ar &boost::serialization::make_array(colnums.get(), max_vec_len);
+  else
+    Assert(colnums.get() == nullptr, ExcInternalError());
 }
 
 
@@ -1603,11 +1610,21 @@ SparsityPatternBase::load(Archive &ar, const unsigned int)
 
   ar &max_dim &rows &cols &max_vec_len &max_row_length &compressed;
 
-  rowstart = std::make_unique<std::size_t[]>(max_dim + 1);
-  colnums  = std::make_unique<size_type[]>(max_vec_len);
+  if (max_dim != 0)
+    {
+      rowstart = std::make_unique<std::size_t[]>(max_dim + 1);
+      ar &boost::serialization::make_array(rowstart.get(), max_dim + 1);
+    }
+  else
+    rowstart.reset();
 
-  ar &boost::serialization::make_array(rowstart.get(), max_dim + 1);
-  ar &boost::serialization::make_array(colnums.get(), max_vec_len);
+  if (max_vec_len != 0)
+    {
+      colnums = std::make_unique<size_type[]>(max_vec_len);
+      ar &boost::serialization::make_array(colnums.get(), max_vec_len);
+    }
+  else
+    colnums.reset();
 }
 
 

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.