Skip to content

Commit

Permalink
parse-options: allow omitting option help text
Browse files Browse the repository at this point in the history
1b68387 (builtin/receive-pack.c: use parse_options API, 2016-03-02)
added the options --stateless-rpc, --advertise-refs and
--reject-thin-pack-for-testing with a NULL `help` string; 03831ef
(difftool: implement the functionality in the builtin, 2017-01-19)
similarly added the "helpless" option --prompt.  Presumably this was
done because all four options are hidden and self-explanatory.

They cause a NULL pointer dereference when using the option --help-all
with their respective tool, though.  Handle such options gracefully
instead by turning the NULL pointer into an empty string at the top of
the loop, always printing a newline at the end and passing through the
separating newlines from the help text.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
rscharfe authored and gitster committed Aug 28, 2023
1 parent 6807fcf commit cd52d9e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions parse-options.c
Expand Up @@ -1186,14 +1186,15 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
continue;
}

for (cp = _(opts->help); *cp; cp = np) {
for (cp = opts->help ? _(opts->help) : ""; *cp; cp = np) {
np = strchrnul(cp, '\n');
usage_padding(outfile, pos);
fprintf(outfile, "%.*s\n", (int)(np - cp), cp);
if (*np)
np++;
usage_padding(outfile, pos);
fwrite(cp, 1, np - cp, outfile);
pos = 0;
}
fputc('\n', outfile);

if (positive_name) {
if (find_option_by_long_name(all_opts, positive_name))
Expand Down

0 comments on commit cd52d9e

Please sign in to comment.