Skip to content

Null-check physics list before dereferencing it#145

Merged
maureeungaro merged 1 commit into
gemc:mainfrom
zhaozhiwen:fix/130-physlist-null-check
Jun 13, 2026
Merged

Null-check physics list before dereferencing it#145
maureeungaro merged 1 commit into
gemc:mainfrom
zhaozhiwen:fix/130-physlist-null-check

Conversation

@zhaozhiwen

Copy link
Copy Markdown
Collaborator

g4alt::G4PhysListFactory::GetReferencePhysList() returns nullptr for an unrecognized list name, but RegisterPhysics() was called before the if (!physList) guard — a typo'd physics-list name segfaulted instead of emitting ERR_PHYSLISTERROR. The null check now runs before the dereference. log->error is [[noreturn]], so the null path terminates cleanly before RegisterPhysics (also avoiding the leaked G4StepLimiterPhysics).

Validation: translation unit recompiled cleanly with Geant4 11.4.1 / ROOT 6.38 / Qt 6.9 (ghcr.io/gemc/src:dev-almalinux-10).

Fixes #130

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 gemc#130

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@maureeungaro maureeungaro merged commit 6db5fa6 into gemc:main Jun 13, 2026
41 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Medium] GPhysics dereferences possibly-null physics list before the null check

2 participants