From: Junio C Hamano <gitster@pobox.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>
Subject: Re: [PATCH 5/6] bugreport.c: tweak cmd_bugreport() to use __attribute__((printf))
Date: Mon, 12 Jul 2021 12:39:55 -0700 [thread overview]
Message-ID: <xmqqczrn48z8.fsf@gitster.g> (raw)
In-Reply-To: <patch-5.6-daca344a165-20210710T084445Z-avarab@gmail.com> ("Ævar Arnfjörð Bjarmason"'s message of "Sat, 10 Jul 2021 10:47:31 +0200")
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> 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.
next prev parent reply other threads:[~2021-07-12 19:40 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-10 8:47 [PATCH 0/6] add missing __attribute__((format)) Ævar Arnfjörð Bjarmason
2021-07-10 8:47 ` [PATCH 1/6] *.c static functions: don't forward-declare __attribute__ Ævar Arnfjörð Bjarmason
2021-07-10 8:47 ` [PATCH 2/6] sequencer.c: move static function to avoid forward decl Ævar Arnfjörð Bjarmason
2021-07-10 8:47 ` [PATCH 3/6] *.c static functions: add missing __attribute__((format)) Ævar Arnfjörð Bjarmason
2021-07-10 8:47 ` [PATCH 4/6] *.h: add a few " Ævar Arnfjörð Bjarmason
2021-07-11 23:05 ` Ævar Arnfjörð Bjarmason
2021-07-12 20:09 ` Jeff King
2021-07-10 8:47 ` [PATCH 5/6] bugreport.c: tweak cmd_bugreport() to use __attribute__((printf)) Ævar Arnfjörð Bjarmason
2021-07-12 19:39 ` Junio C Hamano [this message]
2021-07-10 8:47 ` [PATCH 6/6] git-compat-util.h: add __attribute__((printf)) to git_*printf* Ævar Arnfjörð Bjarmason
2021-07-12 20:13 ` Jeff King
2021-07-12 20:26 ` Randall S. Becker
2021-07-12 21:45 ` Jeff King
2021-07-12 21:58 ` Randall S. Becker
2021-07-12 20:14 ` [PATCH 0/6] add missing __attribute__((format)) Jeff King
2021-07-13 8:05 ` [PATCH v2 " Ævar Arnfjörð Bjarmason
2021-07-13 8:05 ` [PATCH v2 1/6] *.c static functions: don't forward-declare __attribute__ Ævar Arnfjörð Bjarmason
2021-07-13 8:05 ` [PATCH v2 2/6] sequencer.c: move static function to avoid forward decl Ævar Arnfjörð Bjarmason
2021-07-13 8:05 ` [PATCH v2 3/6] *.c static functions: add missing __attribute__((format)) Ævar Arnfjörð Bjarmason
2021-07-13 8:05 ` [PATCH v2 4/6] *.h: add a few " Ævar Arnfjörð Bjarmason
2021-07-13 8:05 ` [PATCH v2 5/6] advice.h: add missing __attribute__((format)) & fix usage Ævar Arnfjörð Bjarmason
2021-07-13 8:05 ` [PATCH v2 6/6] strbuf.h: add a comment about "missing" strftime() checking Ævar Arnfjörð Bjarmason
2021-07-13 21:15 ` Jeff King
2021-07-13 21:17 ` [PATCH v2 0/6] add missing __attribute__((format)) Jeff King
2021-07-13 22:29 ` Junio C Hamano
2021-07-13 23:05 ` Ævar Arnfjörð Bjarmason
2021-07-14 0:15 ` [PATCH v3 0/5] " Ævar Arnfjörð Bjarmason
2021-07-14 0:15 ` [PATCH v3 1/5] *.c static functions: don't forward-declare __attribute__ Ævar Arnfjörð Bjarmason
2021-07-14 0:15 ` [PATCH v3 2/5] sequencer.c: move static function to avoid forward decl Ævar Arnfjörð Bjarmason
2021-07-14 0:15 ` [PATCH v3 3/5] *.c static functions: add missing __attribute__((format)) Ævar Arnfjörð Bjarmason
2021-07-14 0:15 ` [PATCH v3 4/5] *.h: add a few " Ævar Arnfjörð Bjarmason
2021-07-14 0:15 ` [PATCH v3 5/5] advice.h: add missing __attribute__((format)) & fix usage Ævar Arnfjörð Bjarmason
2021-07-14 16:07 ` [PATCH v3 0/5] add missing __attribute__((format)) Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqczrn48z8.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).