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>

Jeff King committed Oct 17, 2022 at 21:01 UTC 0e5a87e0422ff308641199d1afe94b58e1249bc0
1 file changed +3
diff.c
+3
@@ -2488,6 +2488,9 @@ static int diffstat_consume(void *priv, char *line, unsigned long len)
2488 struct diffstat_t *diffstat = priv;
2489 struct diffstat_file *x = diffstat->files[diffstat->nr - 1];
2490
2491 + if (!len)
2492 + BUG("xdiff fed us an empty line");
2493 +
2494 if (line[0] == '+')
2495 x->added++;
2496 else if (line[0] == '-')