From b17e8104fdab3eb471ebd5b25ae2b5e44da882fe Mon Sep 17 00:00:00 2001 From: Zhiwen Zhao Date: Fri, 12 Jun 2026 22:33:19 -0400 Subject: [PATCH] Null-check physics list before dereferencing it GetReferencePhysList() returns nullptr for an unrecognized list name, but RegisterPhysics() was called before the null check, segfaulting on a typo instead of emitting ERR_PHYSLISTERROR. Move the check ahead of the dereference; log->error is [[noreturn]], so the null path terminates cleanly before RegisterPhysics. Fixes #130 Co-Authored-By: Claude Fable 5 --- gemc/gphysics/gphysics.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gemc/gphysics/gphysics.cc b/gemc/gphysics/gphysics.cc index e72bc11c..f9d44e4a 100644 --- a/gemc/gphysics/gphysics.cc +++ b/gemc/gphysics/gphysics.cc @@ -56,12 +56,12 @@ GPhysics::GPhysics(const std::shared_ptr& gopts) : physList = factory.GetReferencePhysList(g4physList); + if (!physList) { log->error(ERR_PHYSLISTERROR, "physics list <" + gphysList + "> could not be loaded."); } + // Register step limiters (module default add-on). // This is intentionally registered even when users select a standard reference list. physList->RegisterPhysics(new G4StepLimiterPhysics()); - if (!physList) { log->error(ERR_PHYSLISTERROR, "physics list <" + gphysList + "> could not be loaded."); } - log->info(2, "G4PhysListFactory: <" + g4physList + "> loaded."); }