From 50864ee4f455c48896cda9406c296beaaa0a0ce6 Mon Sep 17 00:00:00 2001 From: John Peterson Date: Wed, 29 Apr 2026 08:15:41 -0500 Subject: [PATCH 1/2] AnalyticFunction: Assert that relevant function pointer is non-nullptr before using It is currently possible to construct an AnalyticFunction with either an OutputFunction pointer or an OutputVectorFunction pointer, but System::reinit_constraints() expects to be able to use the void-returning AnalyticFunction::operator(), which in turn uses _vector_fptr without first asserting it is valid. I guess we never did this combination of things before, but it came up for me recently in an example created by claude. Program received signal SIGSEGV, Segmentation fault. 0x0000000000000000 in ?? () (gdb) bt (gdb) f 1 127 this->_vector_fptr(output, p, time); (gdb) p _vector_fptr $1 = (libMesh::AnalyticFunction::OutputVectorFunction) 0x0 --- include/numerics/analytic_function.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/numerics/analytic_function.h b/include/numerics/analytic_function.h index 9dfbb27ded..c333bd31a2 100644 --- a/include/numerics/analytic_function.h +++ b/include/numerics/analytic_function.h @@ -111,7 +111,8 @@ inline Output AnalyticFunction::operator() (const Point & p, const Real time) { - libmesh_assert (this->initialized()); + libmesh_assert(this->initialized()); + libmesh_assert(_number_fptr); return (this->_number_fptr(p, time)); } @@ -123,7 +124,8 @@ void AnalyticFunction::operator() (const Point & p, const Real time, DenseVector & output) { - libmesh_assert (this->initialized()); + libmesh_assert(this->initialized()); + libmesh_assert(_vector_fptr); this->_vector_fptr(output, p, time); return; } From fc0e1bc03dec508137372bbb425536af96d5a9d5 Mon Sep 17 00:00:00 2001 From: John Peterson Date: Wed, 29 Apr 2026 08:41:45 -0500 Subject: [PATCH 2/2] Add messages to the asserts --- include/numerics/analytic_function.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/numerics/analytic_function.h b/include/numerics/analytic_function.h index c333bd31a2..ecaae0f23f 100644 --- a/include/numerics/analytic_function.h +++ b/include/numerics/analytic_function.h @@ -112,7 +112,9 @@ Output AnalyticFunction::operator() (const Point & p, const Real time) { libmesh_assert(this->initialized()); - libmesh_assert(_number_fptr); + libmesh_assert_msg(_number_fptr, + "You must construct AnalyticFunction with a scalar-valued " + "function in order to use this operator() override."); return (this->_number_fptr(p, time)); } @@ -125,7 +127,9 @@ void AnalyticFunction::operator() (const Point & p, DenseVector & output) { libmesh_assert(this->initialized()); - libmesh_assert(_vector_fptr); + libmesh_assert_msg(_vector_fptr, + "You must construct AnalyticFunction with a vector-valued " + "function in order to use this operator() override."); this->_vector_fptr(output, p, time); return; }