git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Ramsay Jones <ramsay@ramsayjones.plus.com>,
	Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>
Subject: Re: [PATCH] ls-files: don't try to prune an empty index
Date: Sun, 16 Jul 2017 05:52:42 +0200	[thread overview]
Message-ID: <ae5359cf-a480-f357-cb51-78f9d4cc431c@web.de> (raw)
In-Reply-To: <8fdcc21d-ccf9-7594-4d69-dfcad580da32@ramsayjones.plus.com>

Am 16.07.2017 um 02:28 schrieb Ramsay Jones:
> 
> 
> On 15/07/17 21:11, René Scharfe wrote:
>> Exit early when asked to prune an index that contains no
>> entries to begin with.  This avoids pointer arithmetic on
>> istate->cache, which is possibly NULL in that case.
>>
>> Found with Clang's UBSan.
>>
>> Signed-off-by: Rene Scharfe <l.s.r@web.de>
>> ---
>>   builtin/ls-files.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/builtin/ls-files.c b/builtin/ls-files.c
>> index b8514a0029..adf572da68 100644
>> --- a/builtin/ls-files.c
>> +++ b/builtin/ls-files.c
>> @@ -362,7 +362,7 @@ static void prune_index(struct index_state *istate,
>>       int pos;
>>       unsigned int first, last;
>>
>> -    if (!prefix)
>> +    if (!prefix || !istate->cache_nr)
>>           return;
>>       pos = index_name_pos(istate, prefix, prefixlen);
>>       if (pos < 0)
> 
> My patch looked like:
> 
> -       if (!prefix)
> +       if (!prefix || !istate->cache || istate->cache_nr == 0)
> 
> ... which is probably a bit 'belt-n-braces'. ;-)

Not checking for !istate->cache at this point is a good thing, I think.
If we have entries, then ->cache must not be NULL, and if it is we'd get
a segfault, notifying us that we have a bug.  We could add an assert to
state this requirement explicitly, but that would be the topic of a
different patch.

René

  reply	other threads:[~2017-07-16  3:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-15 20:11 [PATCH] ls-files: don't try to prune an empty index René Scharfe
2017-07-16  0:28 ` Ramsay Jones
2017-07-16  3:52   ` René Scharfe [this message]
2017-07-16 10:41 ` Jeff King
2017-07-16 11:06   ` René Scharfe
2017-07-16 11:08     ` Jeff King
2017-07-16 11:15       ` René Scharfe
2017-07-16 11:32         ` René Scharfe
2017-07-16 11:16 ` [PATCH (resend)] " René Scharfe

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=ae5359cf-a480-f357-cb51-78f9d4cc431c@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=ramsay@ramsayjones.plus.com \
    /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).