ls-files: don't try to prune an empty index
authorRené Scharfe <l.s.r@web.de>
Sun, 16 Jul 2017 11:16:01 +0000 (13:16 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Jul 2017 21:55:21 +0000 (14:55 -0700)
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>
builtin/ls-files.c
index dc4a6aa3d951b46220dcb084d3f86ca7a4cc1a29..c6126eae550beb75e7c90094be337efbb48cd3bc 100644 (file)
@@ -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)