builtin/apply: handle parse_binary() failure

In parse_binary() there is: forward = parse_binary_hunk(&buffer, &size, &status, &used); if (!forward && !status) /* there has to be one hunk (forward hunk) */ return error(_("unrecognized binary patch at line %d"), linenr-1); so parse_binary() can return -1, because that's what error() returns. Also parse_binary_hunk() sets "status" to -1 in case of error and parse_binary() does "if (status) return status;". In this case parse_chunk() should not add -1 to the patchsize it computes. It is better for future libification efforts to make it just return -1. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Mar 18, 2016 at 13:30 UTC 484e77615872b2a62775a6a2dcb1cad0f529c5d3
1 file changed +7
builtin/apply.c
+7
@@ -1863,6 +1863,11 @@ static struct fragment *parse_binary_hunk(char **buf_p,
1863 return NULL;
1864 }
1865
1866 +/*
1867 + * Returns:
1868 + * -1 in case of error,
1869 + * the length of the parsed binary patch otherwise
1870 + */
1871 static int parse_binary(char *buffer, unsigned long size, struct patch *patch)
1872 {
1873 /*
@@ -2008,6 +2013,8 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)
2013 linenr++;
2014 used = parse_binary(buffer + hd + llen,
2015 size - hd - llen, patch);
2016 + if (used < 0)
2017 + return -1;
2018 if (used)
2019 patchsize = used + llen;
2020 else