X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-apply.c;h=9641a6479a5325d5d1680d5e313a23e5d536f822;hb=24ff4d56cf400126aa93ac9a5b9d8a21afadf3f6;hp=fc6c7083f76043168bf8024a9fa50b7f767b99bc;hpb=9b25949a07933fb9ce7c10bd309ac176dbe2df2e;p=git.git diff --git a/builtin-apply.c b/builtin-apply.c index fc6c7083f..9641a6479 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -1997,11 +1997,8 @@ static int find_pos(struct image *img, unsigned long backwards, forwards, try; int backwards_lno, forwards_lno, try_lno; - if (preimage->nr > img->nr) - return -1; - /* - * If match_begining or match_end is specified, there is no + * If match_beginning or match_end is specified, there is no * point starting from a wrong line that will never match and * wander around and wait for a match at the specified end. */ @@ -2010,7 +2007,12 @@ static int find_pos(struct image *img, else if (match_end) line = img->nr - preimage->nr; - if (line > img->nr) + /* + * Because the comparison is unsigned, the following test + * will also take care of a negative line number that can + * result when match_end and preimage is larger than the target. + */ + if ((size_t) line > img->nr) line = img->nr; try = 0;