Skip to content

Do not crash on "gemc help" with no topic#160

Merged
maureeungaro merged 1 commit into
gemc:mainfrom
zhaozhiwen:fix/121-help-no-topic
Jun 13, 2026
Merged

Do not crash on "gemc help" with no topic#160
maureeungaro merged 1 commit into
gemc:mainfrom
zhaozhiwen:fix/121-help-no-topic

Conversation

@zhaozhiwen

Copy link
Copy Markdown
Collaborator

The early help handler read argv[i + 1] without a bounds check. For the bare gemc help (the natural way to ask for the help index), i + 1 == argc, so argv[argc] (the null terminator) was passed to the std::string parameter of printOptionOrSwitchHelp, throwing std::logic_error and aborting. Bounds-check i + 1 < argc and fall back to printHelp() (which already exists and exits) when no topic follows.

Validation: ran in the Geant4 11.4.1 dev container — gemc help now prints the help index and exits 0 instead of terminating with an uncaught exception.

Fixes #121

The early help handler read argv[i + 1] without a bounds check. For the
bare "gemc help" (the natural way to ask for the help index), i + 1 ==
argc, so argv[argc] (the null terminator) was passed to the std::string
parameter of printOptionOrSwitchHelp, throwing std::logic_error and
aborting. Bounds-check i + 1 < argc and fall back to printHelp() (which
already exists and exits) when no topic follows.

Verified: "gemc help" now prints the help index and exits 0 instead of
terminating with an uncaught exception (Geant4 11.4.1 dev container).

Fixes gemc#121

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@maureeungaro maureeungaro merged commit 7dbd173 into gemc:main Jun 13, 2026
30 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] gemc help with no topic crashes with std::logic_error (null argv read)

2 participants