From 447abc2b086766464945abad0b33c07cc3ed5821 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 25 Feb 2022 11:14:59 -0700 Subject: [PATCH] Add an assertion for p4est weights. --- source/distributed/tria.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/source/distributed/tria.cc b/source/distributed/tria.cc index 051ea1540a..af2cf7c380 100644 --- a/source/distributed/tria.cc +++ b/source/distributed/tria.cc @@ -1508,8 +1508,17 @@ namespace Assert(this_object->current_pointer < this_object->cell_weights_list.end(), ExcInternalError()); - // get the weight, increment the pointer, and return the weight - return *this_object->current_pointer++; + // Get the weight, increment the pointer, and return the weight. Also + // make sure that we don't exceed the 'int' data type that p4est uses + // to represent weights + const unsigned int weight = *this_object->current_pointer; + ++this_object->current_pointer; + + Assert(weight < std::numeric_limits::max(), + ExcMessage("p4est uses 'signed int' to represent the partition " + "weights for cells. The weight provided here exceeds " + "the maximum value represented as a 'signed int'.")); + return weight; } template -- 2.39.5