From: Wolfgang Bangerth Date: Fri, 7 Jan 2022 07:19:41 +0000 (-0700) Subject: Fix serialization of possibly empty SparsityPattern objects. X-Git-Tag: v9.4.0-rc1~645^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=657fdface666c7f9d961aecef0112cf47cf8a7a4;p=dealii.git Fix serialization of possibly empty SparsityPattern objects. --- diff --git a/include/deal.II/lac/sparsity_pattern.h b/include/deal.II/lac/sparsity_pattern.h index 011acc1acb..0306c6ac89 100644 --- a/include/deal.II/lac/sparsity_pattern.h +++ b/include/deal.II/lac/sparsity_pattern.h @@ -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(max_dim + 1); - colnums = std::make_unique(max_vec_len); + if (max_dim != 0) + { + rowstart = std::make_unique(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(max_vec_len); + ar &boost::serialization::make_array(colnums.get(), max_vec_len); + } + else + colnums.reset(); }