mirror of
https://github.com/jorisvink/kore
synced 2025-03-10 04:59:02 -04:00
use a copy of args when falling back to vasprintf.
This commit is contained in:
parent
552d59248c
commit
5e1cb53f13
@ -82,14 +82,17 @@ void
|
||||
kore_buf_appendv(struct kore_buf *buf, const char *fmt, va_list args)
|
||||
{
|
||||
int l;
|
||||
va_list copy;
|
||||
char *b, sb[BUFSIZ];
|
||||
|
||||
va_copy(copy, args);
|
||||
|
||||
l = vsnprintf(sb, sizeof(sb), fmt, args);
|
||||
if (l == -1)
|
||||
fatal("kore_buf_appendv(): vsnprintf error");
|
||||
|
||||
if ((size_t)l >= sizeof(sb)) {
|
||||
l = vasprintf(&b, fmt, args);
|
||||
l = vasprintf(&b, fmt, copy);
|
||||
if (l == -1)
|
||||
fatal("kore_buf_appendv(): error or truncation");
|
||||
} else {
|
||||
@ -99,6 +102,8 @@ kore_buf_appendv(struct kore_buf *buf, const char *fmt, va_list args)
|
||||
kore_buf_append(buf, b, l);
|
||||
if (b != sb)
|
||||
free(b);
|
||||
|
||||
va_end(copy);
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
x
Reference in New Issue
Block a user