From 23a9df0f30a314853f05148f8feb6664323f0331 Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Fri, 23 Aug 2024 20:09:47 +0200 Subject: [PATCH] common/buf.c: use 0 directly in vsnprintf() This works around a wrong truncation warning in older GCC versions: ``` ../src/common/buf.c:110:10: error: null destination pointer [-Werror=format-truncation=] 110 | int n = vsnprintf(NULL, size, fmt, ap) ``` --- src/common/buf.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/common/buf.c b/src/common/buf.c index d36f64d5..70be9ed0 100644 --- a/src/common/buf.c +++ b/src/common/buf.c @@ -103,18 +103,17 @@ buf_add_fmt(struct buf *s, const char *fmt, ...) if (string_null_or_empty(fmt)) { return; } - size_t size = 0; va_list ap; va_start(ap, fmt); - int n = vsnprintf(NULL, size, fmt, ap); + int n = vsnprintf(NULL, 0, fmt, ap); va_end(ap); if (n < 0) { return; } - size = (size_t)n + 1; + size_t size = (size_t)n + 1; buf_expand(s, s->len + size); va_start(ap, fmt);