git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [PATCH] add_pending_object_with_path(): work around "gcc -O3" complaint
Date: Thu, 10 Jun 2021 09:11:11 -0400	[thread overview]
Message-ID: <YMIPb+9e2PtaLZhl@coredump.intra.peff.net> (raw)
In-Reply-To: <YMIOY6Hp6//yGrFm@coredump.intra.peff.net>

On Thu, Jun 10, 2021 at 09:06:44AM -0400, Jeff King wrote:

> We can work around this by replacing our "did we hit the trailing NUL"
> subscript dereference with a length check. We do not even have to pay
> the cost for an extra strlen(), as we can pass our new length into
> interpret_branch_name(), which was converting our "0" into a call to
> strlen() anyway.
> [...]
> -		if (0 < len && name[len] && buf.len)
> +		if (0 < len && len < namelen && buf.len)
>  			strbuf_addstr(&buf, name + len);

I guess another option would be to drop the check entirely. It is only
protecting us from calling strbuf_addstr() with an empty string, which
is a noop anyway (it would not even cause a useless allocation, since we
know that buf is non-empty, and that it won't need to grow).

I think I still prefer my original solution, though.

-Peff

  reply	other threads:[~2021-06-10 13:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-10 13:06 [PATCH] add_pending_object_with_path(): work around "gcc -O3" complaint Jeff King
2021-06-10 13:11 ` Jeff King [this message]
2021-06-11  3:52   ` 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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YMIPb+9e2PtaLZhl@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).