Skip to content

Commit

Permalink
diffcore-pickaxe: fix infinite loop on zero-length needle
Browse files Browse the repository at this point in the history
The "contains" algorithm runs into an infinite loop if the needle string
has zero length. The loop could be modified to handle this, but it makes
more sense to simply have an empty needle return no matches. Thus, a
command like
  git log -S
produces no output.

We place the check at the top of the function so that we get the same
results with or without --pickaxe-regex. Note that until now,
  git log -S --pickaxe-regex
would match everything, not nothing.

Arguably, an empty pickaxe string should simply produce an error
message; however, this is still a useful assertion to add to the
algorithm at this layer of the code.

Noticed by Bill Lear.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jan 26, 2007
1 parent cb280e1 commit e1b1611
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions diffcore-pickaxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ static unsigned int contains(struct diff_filespec *one,
const char *data;
if (diff_populate_filespec(one, 0))
return 0;
if (!len)
return 0;

sz = one->size;
data = one->data;
Expand Down

0 comments on commit e1b1611

Please sign in to comment.