git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] ls-files: don't try to prune an empty index

From
Jeff King <peff@peff.net>
Date
Jul 16, 2017, 10:41 UTC
Message-ID
<20170716104114.7tfcuilsy3ab74n6@sigill.intra.peff.net>
In-Reply-To
<bbc51fb0-70ce-3b02-274b-31b5dc035e29@web.de>
On Sat, Jul 15, 2017 at 10:11:20PM +0200, René Scharfe wrote:
Show 5 quoted lines
> 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.

Makes sense. We could use MOVE_ARRAY() here, but this is a sensible short-circuit to the whole function.

Looks like a good solution.
Show 13 quoted lines
> 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)

"git am" complained that this does not apply to its blobs. Did you hand-edit?

-Peff
Previous: René ScharfeNext: René Scharfe
Message 4 of 9 in “ls-files: don't try to prune an empty index”
  1. ls-files: don't try to prune an empty indexRené Scharfe, Jul 15, 2017
  2. Ramsay JonesJul 16, 2017
  3. René ScharfeJul 16, 2017
  4. Jeff KingJul 16, 2017
  5. René ScharfeJul 16, 2017
  6. Jeff KingJul 16, 2017
  7. René ScharfeJul 16, 2017
  8. René ScharfeJul 16, 2017
  9. ls-files: don't try to prune an empty indexRené Scharfe, Jul 16, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.