Skip to content

Commit 1dbb600

Browse files
zhaozhiwenclaude
andcommitted
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 <noreply@anthropic.com>
1 parent 48f83e5 commit 1dbb600

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

gemc/goptions/goptions.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ GOptions::GOptions(int argc, char* argv[], const GOptions& user_defined_options)
100100
exit(EXIT_SUCCESS);
101101
}
102102
else if (strcmp(argv[i], "help") == 0) {
103-
printOptionOrSwitchHelp(argv[i + 1]);
103+
// "gemc help <topic>" shows topic help; bare "gemc help" shows the general help index.
104+
if (i + 1 < argc) { printOptionOrSwitchHelp(argv[i + 1]); }
105+
else { printHelp(); }
104106
exit(EXIT_SUCCESS);
105107
}
106108
}

0 commit comments

Comments
 (0)