diff --git a/core/tbuf.c b/core/tbuf.c index c7f3037a3510ab495421361c2f8f68d37b2fca51..92ad5fbb7d8091c5f01c8b8ea2f275b053f49643 100644 --- a/core/tbuf.c +++ b/core/tbuf.c @@ -155,6 +155,9 @@ void tbuf_vprintf(struct tbuf *b, const char *format, va_list ap) { int printed_len; size_t free_len = b->size - b->len; + va_list ap_copy; + + va_copy(ap_copy, ap); tbuf_assert(b); printed_len = vsnprintf(((char *)b->data) + b->len, free_len, format, ap); @@ -166,7 +169,7 @@ void tbuf_vprintf(struct tbuf *b, const char *format, va_list ap) if (free_len <= printed_len) { tbuf_ensure(b, printed_len + 1); free_len = b->size - b->len - 1; - printed_len = vsnprintf(((char *)b->data) + b->len, free_len, format, ap); + printed_len = vsnprintf(((char *)b->data) + b->len, free_len, format, ap_copy); } b->len += printed_len;