From c5809a4296f852fe30a7356854d3d0758fa1bf7f Mon Sep 17 00:00:00 2001 From: lemon Date: Tue, 8 Feb 2022 12:37:45 +0100 Subject: Fix fmt() off-by-one error vsnprintf returns the byte count of the formatted output not including the null terminator, so in the case that len == 1024 the last character of the output was being truncated and not detected by the later check. Changing the greater than comparison to greater than or equal fixes this edge case. --- html.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html.c b/html.c index cefcf5e..ced781a 100644 --- a/html.c +++ b/html.c @@ -59,7 +59,7 @@ char *fmt(const char *format, ...) va_start(args, format); len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); va_end(args); - if (len > sizeof(buf[bufidx])) { + if (len >= sizeof(buf[bufidx])) { fprintf(stderr, "[html.c] string truncated: %s\n", format); exit(1); } -- cgit 1.4.1-21-gabe81