From: Peter Munch Date: Mon, 28 Jun 2021 10:09:24 +0000 (+0200) Subject: CellIDTranslator:: add assert to prevent overflow X-Git-Tag: v9.4.0-rc1~1186^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F12513%2Fhead;p=dealii.git CellIDTranslator:: add assert to prevent overflow --- diff --git a/include/deal.II/grid/cell_id_translator.h b/include/deal.II/grid/cell_id_translator.h index ae5b6d8803..c857ee5724 100644 --- a/include/deal.II/grid/cell_id_translator.h +++ b/include/deal.II/grid/cell_id_translator.h @@ -21,6 +21,8 @@ #include +#include + DEAL_II_NAMESPACE_OPEN namespace internal @@ -119,6 +121,30 @@ namespace internal : n_coarse_cells(n_coarse_cells) , n_global_levels(n_global_levels) { + std::uint64_t max_cell_index = 0; + + for (unsigned int i = 0; i < n_global_levels; ++i) + max_cell_index += + Utilities::pow(GeometryInfo::max_children_per_cell, + i) * + n_coarse_cells; + + max_cell_index -= 1; + + Assert( + max_cell_index <= std::numeric_limits::max(), + ExcMessage( + "You have exceeded the maximal number of possible indices this function " + "can handle. The current setup (n_coarse_cells=" + + std::to_string(n_coarse_cells) + + ", n_global_levels=" + std::to_string(n_global_levels) + ") requires " + + std::to_string(max_cell_index + 1) + + " indices but the current deal.II configuration only supports " + + std::to_string(std::numeric_limits::max()) + + " indices. You may want to consider to build deal.II with 64bit " + "indeces (-D DEAL_II_WITH_64BIT_INDICES=\"ON\") to increase the limit " + "of indices.")); + tree_sizes.push_back(0); for (unsigned int i = 0; i < n_global_levels; ++i) tree_sizes.push_back(