X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=apply.c;h=c50b3a60464ea05307af8e8d1be576cf96415ff0;hb=9c48666aa0745c666593bb7383e17f78c43eb36d;hp=849a8b4485e65c7eac315daca60b781965a1d22e;hpb=6013f17d8852c4b6365e143422e7a85f88efc492;p=git.git diff --git a/apply.c b/apply.c index 849a8b44..c50b3a60 100644 --- a/apply.c +++ b/apply.c @@ -651,7 +651,7 @@ static int parse_git_header(char *line, int len, unsigned int size, struct patch len = linelen(line, size); if (!len || line[len-1] != '\n') break; - for (i = 0; i < sizeof(optable) / sizeof(optable[0]); i++) { + for (i = 0; i < ARRAY_SIZE(optable); i++) { const struct opentry *p = optable + i; int oplen = strlen(p->str); if (len < oplen || memcmp(p->str, line, oplen)) @@ -693,7 +693,7 @@ static int parse_range(const char *line, int len, int offset, const char *expect line += digits; len -= digits; - *p2 = *p1; + *p2 = 1; if (*line == ',') { digits = parse_num(line+1, p2); if (!digits) @@ -834,7 +834,7 @@ static int parse_fragment(char *line, unsigned long size, struct patch *patch, s patch->new_name = NULL; } - if (patch->is_new != !oldlines) + if (patch->is_new && oldlines) return error("new file depends on old contents"); if (patch->is_delete != !newlines) { if (newlines) @@ -901,6 +901,8 @@ static int parse_fragment(char *line, unsigned long size, struct patch *patch, s break; } } + if (oldlines || newlines) + return -1; /* If a fragment ends with an incomplete line, we failed to include * it in the above loop because we hit oldlines == newlines == 0 * before seeing it.