builtin/bugreport.c: use thread-safe localtime_r()

To generate its filename, the 'git bugreport' builtin asks the system for the current time with 'localtime()'. Since this uses a shared buffer, it is not thread-safe. Even though 'git bugreport' is not multi-threaded, using localtime() can trigger some static analysis tools to complain, and a quick $ git grep -oh 'localtime\(_.\)\?' -- **/*.c | sort | uniq -c shows that the only usage of the thread-unsafe 'localtime' is in a piece of documentation. So, convert this instance to use the thread-safe version for consistency, and to appease some analysis tools. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Nov 30, 2020 at 19:30 UTC 4f6460df55cdccdda9d2a0aad4c6b578c007e01a
1 file changed +2 -1
builtin/bugreport.c
+2 -1
@@ -125,6 +125,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix)
125 struct strbuf report_path = STRBUF_INIT;
126 int report = -1;
127 time_t now = time(NULL);
128 + struct tm tm;
129 char *option_output = NULL;
130 char *option_suffix = "%Y-%m-%d-%H%M";
131 const char *user_relative_path = NULL;
@@ -147,7 +148,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix)
148 strbuf_complete(&report_path, '/');
149
150 strbuf_addstr(&report_path, "git-bugreport-");
150 - strbuf_addftime(&report_path, option_suffix, localtime(&now), 0, 0);
151 + strbuf_addftime(&report_path, option_suffix, localtime_r(&now, &tm), 0, 0);
152 strbuf_addstr(&report_path, ".txt");
153
154 switch (safe_create_leading_directories(report_path.buf)) {