From b3b57c69dad91382ccc36ebf5d668454607dd568 Mon Sep 17 00:00:00 2001 From: Jiamu Sun Date: Thu, 14 Mar 2024 04:00:16 +0000 Subject: bugreport.c: fix a crash in `git bugreport` with `--no-suffix` option `git bugreport` does not complain when `--no-suffix` is given, but it leads to a segmentation fault as the it is not prepared to see a NULL assigned to the option_suffix variable. Signed-off-by: Jiamu Sun Acked-by: Taylor Blau Signed-off-by: Junio C Hamano --- builtin/bugreport.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'builtin') diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 3106e56a13..25f860a0d9 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -64,7 +64,8 @@ static void get_populated_hooks(struct strbuf *hook_info, int nongit) } static const char * const bugreport_usage[] = { - N_("git bugreport [(-o | --output-directory) ] [(-s | --suffix) ]\n" + N_("git bugreport [(-o | --output-directory) ]\n" + " [(-s | --suffix) | --no-suffix]\n" " [--diagnose[=]]"), NULL }; @@ -138,8 +139,11 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) strbuf_complete(&report_path, '/'); output_path_len = report_path.len; - strbuf_addstr(&report_path, "git-bugreport-"); - strbuf_addftime(&report_path, option_suffix, localtime_r(&now, &tm), 0, 0); + strbuf_addstr(&report_path, "git-bugreport"); + if (option_suffix) { + strbuf_addch(&report_path, '-'); + strbuf_addftime(&report_path, option_suffix, localtime_r(&now, &tm), 0, 0); + } strbuf_addstr(&report_path, ".txt"); switch (safe_create_leading_directories(report_path.buf)) { -- cgit 1.2.3-korg