git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ls-files: don't try to prune an empty index
@ 2017-07-15 20:11 René Scharfe
  2017-07-16  0:28 ` Ramsay Jones
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: René Scharfe @ 2017-07-15 20:11 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano, Jeff King

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>
---
  builtin/ls-files.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index b8514a0029..adf572da68 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)
-- 
2.13.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-07-16 11:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-15 20:11 [PATCH] ls-files: don't try to prune an empty index René Scharfe
2017-07-16  0:28 ` Ramsay Jones
2017-07-16  3:52   ` René Scharfe
2017-07-16 10:41 ` Jeff King
2017-07-16 11:06   ` René Scharfe
2017-07-16 11:08     ` Jeff King
2017-07-16 11:15       ` René Scharfe
2017-07-16 11:32         ` René Scharfe
2017-07-16 11:16 ` [PATCH (resend)] " René Scharfe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).