ls-files: don't try to prune an empty index
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>
René Scharfe committed
Jul 16, 2017 at 13:16 UTC
168e63554cbd965fee4d0092e02f8170eba7481f
1 file changed
+1
-1
builtin/ls-files.c
+1
-1
@@ -362,7 +362,7 @@ static void prune_index(struct index_state *istate,
362
int pos;
363
unsigned int first, last;
364
365
- if (!prefix)
365
+ if (!prefix || !istate->cache_nr)
366
return;
367
pos = index_name_pos(istate, prefix, prefixlen);
368
if (pos < 0)