diff options
author | René Scharfe <l.s.r@web.de> | 2017-07-16 13:16:01 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-07-17 14:55:21 -0700 |
commit | 168e63554cbd965fee4d0092e02f8170eba7481f (patch) | |
tree | 4c8dab271a4d080f1ba05f91d3ce2d2b3d3ee7fb | |
parent | 177366415b95fb72bc2c37d55a936ff101986285 (diff) | |
download | git-168e63554cbd965fee4d0092e02f8170eba7481f.tar.gz git-168e63554cbd965fee4d0092e02f8170eba7481f.tar.xz |
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>
-rw-r--r-- | builtin/ls-files.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/builtin/ls-files.c b/builtin/ls-files.c index dc4a6aa3d..c6126eae5 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) |