From: Jeff King Date: Fri, 26 Jan 2007 04:48:58 +0000 (-0500) Subject: diffcore-pickaxe: fix infinite loop on zero-length needle X-Git-Tag: v1.5.0-rc3~56 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e1b161161d253a9e7e4cf21cd2ab5b82a4b85273;p=git.git diffcore-pickaxe: fix infinite loop on zero-length needle 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 Signed-off-by: Junio C Hamano --- diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c index de44adabf..286919e71 100644 --- a/diffcore-pickaxe.c +++ b/diffcore-pickaxe.c @@ -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;