From 1dbb600bcfdbfe5094ad1ae949c60a43892664f6 Mon Sep 17 00:00:00 2001 From: Zhiwen Zhao Date: Sat, 13 Jun 2026 00:00:41 -0400 Subject: [PATCH] Don't crash on "gemc help" with no topic 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 #121 Co-Authored-By: Claude Fable 5 --- gemc/goptions/goptions.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gemc/goptions/goptions.cc b/gemc/goptions/goptions.cc index 50304bef..a372ae52 100644 --- a/gemc/goptions/goptions.cc +++ b/gemc/goptions/goptions.cc @@ -100,7 +100,9 @@ GOptions::GOptions(int argc, char* argv[], const GOptions& user_defined_options) exit(EXIT_SUCCESS); } else if (strcmp(argv[i], "help") == 0) { - printOptionOrSwitchHelp(argv[i + 1]); + // "gemc help " shows topic help; bare "gemc help" shows the general help index. + if (i + 1 < argc) { printOptionOrSwitchHelp(argv[i + 1]); } + else { printHelp(); } exit(EXIT_SUCCESS); } }