fix out of bounds

This commit is contained in:
r4 2022-05-29 20:30:14 +02:00
parent f41752b8d8
commit 0627084381

View File

@ -529,10 +529,9 @@ size_t _fmtsv(const char *restrict file, size_t line, char *restrict buf, size_t
.ctx_data = &ctxs, .ctx_data = &ctxs,
.putc_func = _fmts_putc_func, .putc_func = _fmts_putc_func,
}; };
memset(buf, 0, size); /* TODO: Remove this without valgrind complaining. */
_fmtcv(file, line, &ctx, format, args); _fmtcv(file, line, &ctx, format, args);
if (size > 0) if (size > 0)
buf[ctxs.written] = 0; buf[ctxs.written < size - 1 ? ctxs.written : size - 1] = 0;
return ctxs.written; return ctxs.written;
} }