From: Junio C Hamano <gitster@pobox•com>
To: Jeff King <peff@peff•net>
Cc: "Johannes Schindelin" <Johannes.Schindelin@gmx•de>,
"René Scharfe" <l.s.r@web•de>, "Git List" <git@vger•kernel.org>
Subject: Re: [PATCH 2/2] avoid using sha1_to_hex output as printf format
Date: Fri, 08 Jul 2016 10:02:53 -0700 [thread overview]
Message-ID: <xmqqinwgm5aa.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20160708103515.GA19705@sigill.intra.peff.net> (Jeff King's message of "Fri, 8 Jul 2016 06:35:15 -0400")
Jeff King <peff@peff•net> writes:
> On Fri, Jul 08, 2016 at 05:25:26AM -0400, Jeff King wrote:
>
>> diff --git a/commit.c b/commit.c
>> index 3f4f371..9603379 100644
>> --- a/commit.c
>> +++ b/commit.c
>> @@ -1623,7 +1623,7 @@ void print_commit_list(struct commit_list *list,
>> {
>> for ( ; list; list = list->next) {
>> const char *format = list->next ? format_cur : format_last;
>> - printf(format, oid_to_hex(&list->item->object.oid));
>> + printf(format, "%s", oid_to_hex(&list->item->object.oid));
>
> Urgh, this second hunk is clearly bogus. This is a -Wformat-nonliteral
> problem, but not because of oid_to_hex(), but rather because of
> "format". :-/
>
> Here's a corrected patch. But as this has demonstrated the dangers of
> churn, and as it doesn't really get us meaningfully closer to being able
> to use -Wformat-nonliteral, perhaps the best course of action is to just
> drop it (I do think the "walker_say" patch has more inherent value as a
> cleanup, though).
Hmm. While both do look correct, and it is a no-brainer to take
this (corrected) patch, I am not sure how much we care about walkers
these days.
As to the hunk to commit.c that was dropped in this round, the only
caller of print_commit_list() is bisect.c, and it passes "%s\n" to
format_cur and format_last, it seems, so that suggests a more
obvious direction for cleaning things up, I would say.
> -- >8 --
> Subject: [PATCH] avoid using sha1_to_hex output as printf format
>
> We know that it should not contain any percent-signs, but
> it's a good habit not to feed non-literals to printf
> formatters.
>
> Signed-off-by: Jeff King <peff@peff•net>
> ---
> builtin/worktree.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/builtin/worktree.c b/builtin/worktree.c
> index e866844..cce555c 100644
> --- a/builtin/worktree.c
> +++ b/builtin/worktree.c
> @@ -262,7 +262,7 @@ static int add_worktree(const char *path, const char *refname,
> */
> strbuf_reset(&sb);
> strbuf_addf(&sb, "%s/HEAD", sb_repo.buf);
> - write_file(sb.buf, sha1_to_hex(null_sha1));
> + write_file(sb.buf, "%s", sha1_to_hex(null_sha1));
> strbuf_reset(&sb);
> strbuf_addf(&sb, "%s/commondir", sb_repo.buf);
> write_file(sb.buf, "../..");
next prev parent reply other threads:[~2016-07-08 17:03 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-07 20:02 [PATCH] am: ignore return value of write_file() René Scharfe
2016-07-07 20:31 ` Jeff King
2016-07-08 6:37 ` Johannes Schindelin
2016-07-08 6:56 ` Jeff King
2016-07-08 9:04 ` [PATCH 0/8] write_file cleanups Jeff King
2016-07-08 9:06 ` [PATCH 1/8] config: fix bogus fd check when setting up default config Jeff King
2016-07-08 9:08 ` [PATCH 2/8] am: ignore return value of write_file() Jeff King
2016-07-08 9:08 ` [PATCH 3/8] branch: use non-gentle write_file for branch description Jeff King
2016-07-08 9:09 ` [PATCH 4/8] write_file: drop "gently" form Jeff King
2016-07-08 9:10 ` [PATCH 5/8] write_file: use xopen Jeff King
2016-07-08 9:12 ` [PATCH 6/8] write_file: add pointer+len variant Jeff King
2016-07-08 9:12 ` [PATCH 7/8] write_file: add format attribute Jeff King
2016-07-08 9:25 ` Jeff King
2016-07-08 9:25 ` [PATCH 1/2] walker: let walker_say take arbitrary formats Jeff King
2016-07-08 9:25 ` [PATCH 2/2] avoid using sha1_to_hex output as printf format Jeff King
2016-07-08 10:35 ` Jeff King
2016-07-08 17:02 ` Junio C Hamano [this message]
2016-07-08 17:09 ` Junio C Hamano
2016-07-08 21:41 ` Jeff King
2016-07-08 9:12 ` [PATCH 8/8] use write_file_buf where applicable Jeff King
2016-07-08 9:16 ` [PATCH 9/8] branch: use write_file_buf instead of write_file Jeff King
2016-07-08 18:44 ` [PATCH 0/8] write_file cleanups René Scharfe
2016-07-09 14:24 ` [PATCH] am: ignore return value of write_file() Johannes Schindelin
2016-07-10 10:53 ` Johannes Schindelin
2016-07-08 6:33 ` Johannes Schindelin
2016-07-08 18:44 ` René Scharfe
2016-07-08 21:51 ` Jeff King
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=xmqqinwgm5aa.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=Johannes.Schindelin@gmx$(echo .)de \
--cc=git@vger$(echo .)kernel.org \
--cc=l.s.r@web$(echo .)de \
--cc=peff@peff$(echo .)net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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