Skip to content

Commit

Permalink
ls-files: don't try to prune an empty index
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
rscharfe authored and gitster committed Jul 17, 2017
1 parent 1773664 commit 168e635
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion builtin/ls-files.c
Expand Up @@ -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)
Expand Down

0 comments on commit 168e635

Please sign in to comment.