* PATCH] parse-options: allow omitting option help text
@ 2023-08-26 8:06 René Scharfe
2023-08-28 15:19 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2023-08-26 8:06 UTC (permalink / raw)
To: Git List
1b68387e02 (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; 03831ef7b5
(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>
---
parse-options.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index 76d2e76b49..e8e076c3a6 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -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))
--
2.42.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: PATCH] parse-options: allow omitting option help text
2023-08-26 8:06 PATCH] parse-options: allow omitting option help text René Scharfe
@ 2023-08-28 15:19 ` Junio C Hamano
0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2023-08-28 15:19 UTC (permalink / raw)
To: René Scharfe; +Cc: Git List
René Scharfe <l.s.r@web•de> writes:
> 1b68387e02 (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; 03831ef7b5
> (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.
Good find. Will apply. Thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-08-28 15:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-26 8:06 PATCH] parse-options: allow omitting option help text René Scharfe
2023-08-28 15:19 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox