mirror of
https://github.com/labwc/labwc.git
synced 2025-11-02 09:01:47 -05:00
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) ```
This commit is contained in:
parent
b667107d1a
commit
23a9df0f30
1 changed files with 2 additions and 3 deletions
|
|
@ -103,18 +103,17 @@ buf_add_fmt(struct buf *s, const char *fmt, ...)
|
||||||
if (string_null_or_empty(fmt)) {
|
if (string_null_or_empty(fmt)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size_t size = 0;
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
int n = vsnprintf(NULL, size, fmt, ap);
|
int n = vsnprintf(NULL, 0, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
size = (size_t)n + 1;
|
size_t size = (size_t)n + 1;
|
||||||
buf_expand(s, s->len + size);
|
buf_expand(s, s->len + size);
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue