Skip to content

Commit cd52d9e

Browse files
rscharfegitster
authored andcommitted
parse-options: allow omitting option help text
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6807fcf commit cd52d9e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

parse-options.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,14 +1186,15 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
11861186
continue;
11871187
}
11881188

1189-
for (cp = _(opts->help); *cp; cp = np) {
1189+
for (cp = opts->help ? _(opts->help) : ""; *cp; cp = np) {
11901190
np = strchrnul(cp, '\n');
1191-
usage_padding(outfile, pos);
1192-
fprintf(outfile, "%.*s\n", (int)(np - cp), cp);
11931191
if (*np)
11941192
np++;
1193+
usage_padding(outfile, pos);
1194+
fwrite(cp, 1, np - cp, outfile);
11951195
pos = 0;
11961196
}
1197+
fputc('\n', outfile);
11971198

11981199
if (positive_name) {
11991200
if (find_option_by_long_name(all_opts, positive_name))

0 commit comments

Comments
 (0)