From: René Scharfe Date: Sun, 16 Jul 2017 11:16:01 +0000 (+0200) Subject: ls-files: don't try to prune an empty index X-Git-Tag: v2.14.2~54^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=168e63554cbd965fee4d0092e02f8170eba7481f;p=thirdparty%2Fgit.git 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 Signed-off-by: Junio C Hamano --- diff --git a/builtin/ls-files.c b/builtin/ls-files.c index dc4a6aa3d9..c6126eae55 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)