git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 5/6] bugreport.c: tweak cmd_bugreport() to use __attribute__((printf))

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 12, 2021, 19:39 UTC
Message-ID
<xmqqczrn48z8.fsf@gitster.g>
In-Reply-To
<patch-5.6-daca344a165-20210710T084445Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 31 quoted lines
> As noted in the preceding commit we had no __attribute__((format))
> check for strbuf_addftime(), and furthermore had no in-tree user that
> passed it a fixed string.
>
> Let's tweak this codepath added in 238b439d698 (bugreport: add tool to
> generate debugging info, 2020-04-16) to make use of the compile-time
> check.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  builtin/bugreport.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/bugreport.c b/builtin/bugreport.c
> index 9915a5841de..02edfb9a047 100644
> --- a/builtin/bugreport.c
> +++ b/builtin/bugreport.c
> @@ -127,7 +127,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix)
>  	time_t now = time(NULL);
>  	struct tm tm;
>  	char *option_output = NULL;
> -	char *option_suffix = "%Y-%m-%d-%H%M";
> +	char *option_suffix = NULL;
> ...
> +	if (option_suffix)
> +		strbuf_addftime(&report_path, option_suffix, localtime_r(&now, &tm), 0, 0);
> +	else
> +		strbuf_addftime(&report_path, "%Y-%m-%d-%H%M", localtime_r(&now, &tm), 0, 0);
>  	strbuf_addstr(&report_path, ".txt");
>  
>  	switch (safe_create_leading_directories(report_path.buf)) {

The use of "the variable option_suffix whose default value is '%Y-%m-%d-%H%M'" may happen to be only to generate report_path in the current code, but there is little reason to expect that will stay to be true. With this change, however, future developers has to know that option_suffix may not have its default value in it and they need to do the "if it is NULL, then use the default", and without any benefit of proprocessor macro.

And in exchange of it, we gain what? Letting some compilers ensure that "%Y-%m-%d-%H%M" is a valid strftime format string? That does not sound all that much interesting.

This step I am not impressed all that much, even though the earlier clean-up steps all looked sensible.

Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 5 of 33 in “add missing __attribute__((format))”
  1. 0/6 add missing __attribute__((format))Ævar Arnfjörð Bjarmason, Jul 10, 2021
  2. 1/6 *.c static functions: don't forward-declare __attribute__Ævar Arnfjörð Bjarmason, Jul 10, 2021
  3. 3/6 *.c static functions: add missing __attribute__((format))Ævar Arnfjörð Bjarmason, Jul 10, 2021
  4. 5/6 bugreport.c: tweak cmd_bugreport() to use __attribute__((printf))Ævar Arnfjörð Bjarmason, Jul 10, 2021
  5. Junio C HamanoJul 12, 2021
  6. 2/6 sequencer.c: move static function to avoid forward declÆvar Arnfjörð Bjarmason, Jul 10, 2021
  7. 6/6 git-compat-util.h: add __attribute__((printf)) to git_*printf*Ævar Arnfjörð Bjarmason, Jul 10, 2021
  8. Jeff KingJul 12, 2021
  9. Randall S. BeckerJul 12, 2021
  10. Jeff KingJul 12, 2021
  11. Randall S. BeckerJul 12, 2021
  12. 4/6 *.h: add a few missing __attribute__((format))Ævar Arnfjörð Bjarmason, Jul 10, 2021
  13. Ævar Arnfjörð BjarmasonJul 11, 2021
  14. Jeff KingJul 12, 2021
  15. Jeff KingJul 12, 2021
  16. 0/6 add missing __attribute__((format))Ævar Arnfjörð Bjarmason, Jul 13, 2021
  17. 1/6 *.c static functions: don't forward-declare __attribute__Ævar Arnfjörð Bjarmason, Jul 13, 2021
  18. 2/6 sequencer.c: move static function to avoid forward declÆvar Arnfjörð Bjarmason, Jul 13, 2021
  19. 3/6 *.c static functions: add missing __attribute__((format))Ævar Arnfjörð Bjarmason, Jul 13, 2021
  20. 4/6 *.h: add a few missing __attribute__((format))Ævar Arnfjörð Bjarmason, Jul 13, 2021
  21. 5/6 advice.h: add missing __attribute__((format)) & fix usageÆvar Arnfjörð Bjarmason, Jul 13, 2021
  22. 6/6 strbuf.h: add a comment about "missing" strftime() checkingÆvar Arnfjörð Bjarmason, Jul 13, 2021
  23. Jeff KingJul 13, 2021
  24. Jeff KingJul 13, 2021
  25. Junio C HamanoJul 13, 2021
  26. Ævar Arnfjörð BjarmasonJul 13, 2021
  27. 0/5 add missing __attribute__((format))Ævar Arnfjörð Bjarmason, Jul 14, 2021
  28. 1/5 *.c static functions: don't forward-declare __attribute__Ævar Arnfjörð Bjarmason, Jul 14, 2021
  29. 2/5 sequencer.c: move static function to avoid forward declÆvar Arnfjörð Bjarmason, Jul 14, 2021
  30. 3/5 *.c static functions: add missing __attribute__((format))Ævar Arnfjörð Bjarmason, Jul 14, 2021
  31. 5/5 advice.h: add missing __attribute__((format)) & fix usageÆvar Arnfjörð Bjarmason, Jul 14, 2021
  32. 4/5 *.h: add a few missing __attribute__((format))Ævar Arnfjörð Bjarmason, Jul 14, 2021
  33. Junio C HamanoJul 14, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.