From 0627084381e791ef983161d767069115b0ad0338 Mon Sep 17 00:00:00 2001 From: r4 Date: Sun, 29 May 2022 20:30:14 +0200 Subject: [PATCH] fix out of bounds --- src/ds/fmt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ds/fmt.c b/src/ds/fmt.c index bd4a1d5..b467848 100644 --- a/src/ds/fmt.c +++ b/src/ds/fmt.c @@ -529,10 +529,9 @@ size_t _fmtsv(const char *restrict file, size_t line, char *restrict buf, size_t .ctx_data = &ctxs, .putc_func = _fmts_putc_func, }; - memset(buf, 0, size); /* TODO: Remove this without valgrind complaining. */ _fmtcv(file, line, &ctx, format, args); if (size > 0) - buf[ctxs.written] = 0; + buf[ctxs.written < size - 1 ? ctxs.written : size - 1] = 0; return ctxs.written; }