From: Rene Gassmoeller Date: Thu, 19 Jul 2018 00:42:35 +0000 (-0700) Subject: Avoid out of bounds memory access X-Git-Tag: v9.0.1~5^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=daae8b2999b360baf9368e2af939fd470b6f93d8;p=dealii.git Avoid out of bounds memory access --- diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index ea47ebd793..b05c8be770 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -405,22 +405,22 @@ namespace DataOutBase write_gmv_reorder_data_vectors (const std::vector > &patches, Table<2,Number> &data_vectors) { - // unlike in the main function, we - // don't have here the data_names - // field, so we initialize it with - // the number of data sets in the - // first patch. the equivalence of - // these two definitions is checked - // in the main function. - - // we have to take care, however, whether the - // points are appended to the end of the - // patch->data table - const unsigned int n_data_sets - =patches[0].points_are_available ? (patches[0].data.n_rows() - spacedim) : patches[0].data.n_rows(); - - Assert (data_vectors.size()[0] == n_data_sets, - ExcInternalError()); + // If there is nothing to write, just return + if (patches.size() == 0) + return; + + // unlike in the main function, we don't have here the data_names field, + // so we initialize it with the number of data sets in the first patch. + // the equivalence of these two definitions is checked in the main + // function. + + // we have to take care, however, whether the points are appended to the + // end of the patch->data table + const unsigned int n_data_sets = patches[0].points_are_available ? + (patches[0].data.n_rows() - spacedim) : + patches[0].data.n_rows(); + + Assert(data_vectors.size()[0] == n_data_sets, ExcInternalError()); // loop over all patches unsigned int next_value = 0; @@ -6845,20 +6845,16 @@ void DataOutBase::write_filtered_data (const std::vector > & Threads::Task<> reorder_task; #ifndef DEAL_II_WITH_MPI - // verify that there are indeed - // patches to be written out. most - // of the times, people just forget - // to call build_patches when there - // are no patches, so a warning is - // in order. that said, the - // assertion is disabled if we - // support MPI since then it can - // happen that on the coarsest - // mesh, a processor simply has no - // cells it actually owns, and in - // that case it is legit if there - // are no patches - Assert (patches.size() > 0, ExcNoPatches()); + // verify that there are indeed patches to be written out. most of the times, + // people just forget to call build_patches when there are no patches, so a + // warning is in order. that said, the assertion is disabled if we support MPI + // since then it can happen that on the coarsest mesh, a processor simply has + // no cells it actually owns, and in that case it is legit if there are no + // patches + Assert(patches.size() > 0, ExcNoPatches()); +#else + if (patches.size() == 0) + return; #endif compute_sizes(patches, n_node, n_cell); diff --git a/source/base/mpi.cc b/source/base/mpi.cc index 38e8122f10..3391d81cc7 100644 --- a/source/base/mpi.cc +++ b/source/base/mpi.cc @@ -23,7 +23,7 @@ #include #include -#include +#include #include #ifdef DEAL_II_WITH_TRILINOS