1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-06 21:56:12 +02:00

diffstat_consume(): assert non-zero length

The callback interface for xdiff_emit_line_fn gives us a line/len pair,
but diffstat_consume() never looks at "len". At first glance this seems
like a bug that could cause us to read further than xdiff intends. But
in practice, we read only the first character, and xdiff would never
pass us an empty line.

Let's add a run-time assertion that this is true, which clarifies our
assumption and silences -Wunused-parameter.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2022-10-17 21:01:17 -04:00 committed by Junio C Hamano
parent 3dcec76d9d
commit 0e5a87e042

3
diff.c
View File

@ -2488,6 +2488,9 @@ static int diffstat_consume(void *priv, char *line, unsigned long len)
struct diffstat_t *diffstat = priv;
struct diffstat_file *x = diffstat->files[diffstat->nr - 1];
if (!len)
BUG("xdiff fed us an empty line");
if (line[0] == '+')
x->added++;
else if (line[0] == '-')