{"thread":{"id":"60155","subject":"PATCH] parse-options: allow omitting option help text","startedAt":"2023-08-26T08:06:40Z","lastAt":"2023-08-28T15:20:48Z","messageCount":2,"participants":["René Scharfe","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"481040","messageId":"2b08dc43-621d-2170-c4a6-c2aac33a9a19@web.de","threadId":"60155","inReplyTo":null,"subject":"PATCH] parse-options: allow omitting option help text","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2023-08-26T08:06:00Z","receivedAt":"2023-08-26T08:06:40Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"1b68387e02 (builtin/receive-pack.c: use parse_options API, 2016-03-02)\nadded the options --stateless-rpc, --advertise-refs and\n--reject-thin-pack-for-testing with a NULL `help` string; 03831ef7b5\n(difftool: implement the functionality in the builtin, 2017-01-19)\nsimilarly added the \"helpless\" option --prompt.  Presumably this was\ndone because all four options are hidden and self-explanatory.\n\nThey cause a NULL pointer dereference when using the option --help-all\nwith their respective tool, though.  Handle such options gracefully\ninstead by turning the NULL pointer into an empty string at the top of\nthe loop, always printing a newline at the end and passing through the\nseparating newlines from the help text.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n parse-options.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/parse-options.c b/parse-options.c\nindex 76d2e76b49..e8e076c3a6 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -1186,14 +1186,15 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t\n \t\t\tcontinue;\n \t\t}\n\n-\t\tfor (cp = _(opts->help); *cp; cp = np) {\n+\t\tfor (cp = opts->help ? _(opts->help) : \"\"; *cp; cp = np) {\n \t\t\tnp = strchrnul(cp, '\\n');\n-\t\t\tusage_padding(outfile, pos);\n-\t\t\tfprintf(outfile, \"%.*s\\n\", (int)(np - cp), cp);\n \t\t\tif (*np)\n \t\t\t\tnp++;\n+\t\t\tusage_padding(outfile, pos);\n+\t\t\tfwrite(cp, 1, np - cp, outfile);\n \t\t\tpos = 0;\n \t\t}\n+\t\tfputc('\\n', outfile);\n\n \t\tif (positive_name) {\n \t\t\tif (find_option_by_long_name(all_opts, positive_name))\n--\n2.42.0\n"},{"id":"481052","messageId":"xmqqr0nnjisv.fsf@gitster.g","threadId":"60155","inReplyTo":"2b08dc43-621d-2170-c4a6-c2aac33a9a19@web.de","subject":"Re: PATCH] parse-options: allow omitting option help text","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-08-28T15:19:44Z","receivedAt":"2023-08-28T15:20:48Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"René Scharfe <l.s.r@web.de> writes:\n\n> 1b68387e02 (builtin/receive-pack.c: use parse_options API, 2016-03-02)\n> added the options --stateless-rpc, --advertise-refs and\n> --reject-thin-pack-for-testing with a NULL `help` string; 03831ef7b5\n> (difftool: implement the functionality in the builtin, 2017-01-19)\n> similarly added the \"helpless\" option --prompt.  Presumably this was\n> done because all four options are hidden and self-explanatory.\n>\n> They cause a NULL pointer dereference when using the option --help-all\n> with their respective tool, though.\n\nGood find.  Will apply.  Thanks.\n"}]}