grep: use xsnprintf to format failure message
This looks at first glance like the sprintf can overflow our buffer, but it's actually fine; the p->origin string is something constant and small, like "command line" or "-e option". Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Sep 24, 2015 at 17:06 UTC
19bdd3e7e160a0b000c15d8bf6d33f4149e3f911
1 file changed
+2
-2
grep.c
+2
-2
@@ -306,9 +306,9 @@ static NORETURN void compile_regexp_failed(const struct grep_pat *p,
306
char where[1024];
307
308
if (p->no)
309
- sprintf(where, "In '%s' at %d, ", p->origin, p->no);
309
+ xsnprintf(where, sizeof(where), "In '%s' at %d, ", p->origin, p->no);
310
else if (p->origin)
311
- sprintf(where, "%s, ", p->origin);
311
+ xsnprintf(where, sizeof(where), "%s, ", p->origin);
312
else
313
where[0] = 0;
314