]> git.mdlowis.com Git - proto/labwc.git/commitdiff
common/buf.c: use 0 directly in vsnprintf()
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Fri, 23 Aug 2024 18:09:47 +0000 (20:09 +0200)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Fri, 23 Aug 2024 18:20:50 +0000 (20:20 +0200)
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

index d36f64d5defc695c7a239933a23ff6a2e8e26f55..70be9ed0d7d2b1c2fdbdd9d8521a739a8fd6a405 100644 (file)
@@ -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);