From: Daniel Arndt Date: Tue, 13 Aug 2024 19:29:13 +0000 (-0600) Subject: Fix undefined behavior when advancing nullptr X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F17512%2Fhead;p=dealii.git Fix undefined behavior when advancing nullptr --- diff --git a/include/deal.II/dofs/dof_accessor.templates.h b/include/deal.II/dofs/dof_accessor.templates.h index 93702dbce2..c3afa34c61 100644 --- a/include/deal.II/dofs/dof_accessor.templates.h +++ b/include/deal.II/dofs/dof_accessor.templates.h @@ -533,11 +533,15 @@ namespace internal object_dof_indices.data() + range.first; // process dofs - for (unsigned int i = 0; i < range.second; ++i, ++dof_indices_ptr) - process( - stored_indices[(structdim == 0 || structdim == dim) ? i : - mapping(i)], - dof_indices_ptr); + for (unsigned int i = 0; i < range.second; ++i) + { + process( + stored_indices[(structdim == 0 || structdim == dim) ? i : + mapping(i)], + dof_indices_ptr); + if (dof_indices_ptr != nullptr) + ++dof_indices_ptr; + } } @@ -1143,8 +1147,11 @@ namespace internal dof_indices_ptr, dof_processor); - AssertDimension(n_dof_indices(accessor, fe_index, count_level_dofs), - dof_indices_ptr - get_array_ptr(const_dof_indices)); + if (dof_indices_ptr != nullptr) + { + AssertDimension(n_dof_indices(accessor, fe_index, count_level_dofs), + dof_indices_ptr - get_array_ptr(const_dof_indices)); + } // PM: This is a part that should not be reached since it indicates that // an object (and/or its subobjects) is not active. However,