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

Jeff King <peff@peff.net> writes:

> 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.

It may still work without the guard but it is not apparent to the
readers if it just happens to work by accident or by design.  At
least the guard makes it clear what is going on, I would think.


      reply	other threads:[~2021-06-11  3:52 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
2021-06-11  3:52   ` Junio C Hamano [this message]

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=xmqqzgvx3vo7.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.
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).