From 98fa034c53ffb3ca6831251911a84c9a519bae83 Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Mon, 7 May 2018 23:25:58 +0930 Subject: [PATCH] Fix use of va_copy() in logging functions --- log.c | 10 +++++----- xprintf.c | 10 ++++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/log.c b/log.c index 163bef96..7540a881 100644 --- a/log.c +++ b/log.c @@ -264,10 +264,7 @@ static void iterator_vprintf_nl(struct log_output_iterator *it, int level, struc assert(current_iterator); log_start_line(it, level); whence_prefix(it, whence); - va_list ap1; - va_copy(ap1, ap); - vxprintf(it->xpf, fmt, ap1); - va_end(ap1); + vxprintf(it->xpf, fmt, ap); log_end_line(it, level); } @@ -300,7 +297,10 @@ void serval_vlogf(int level, struct __sourceloc whence, const char *fmt, va_list if (is_log_available(&it)) { current_iterator = ⁢ print_newdate(&it); - iterator_vprintf_nl(&it, level, whence, fmt, ap); + va_list ap1; + va_copy(ap1, ap); + iterator_vprintf_nl(&it, level, whence, fmt, ap1); + va_end(ap1); log_flush(&it); current_iterator = NULL; } diff --git a/xprintf.c b/xprintf.c index 2696793d..ee2b8708 100644 --- a/xprintf.c +++ b/xprintf.c @@ -105,14 +105,20 @@ void _cx_vprintf_mallocbuf(void *context, const char *fmt, va_list ap) if (mb->current) { if (mb->current + 1 >= mb->buffer + mb->size) grow_mallocbuf(mb, 1024); - int n = vsnprintf(mb->current, mb->buffer + mb->size - mb->current, fmt, ap); + va_list ap1; + va_copy(ap1, ap); + int n = vsnprintf(mb->current, mb->buffer + mb->size - mb->current, fmt, ap1); + va_end(ap1); char *newcurrent = mb->current + n; char *end = mb->buffer + mb->size; if (newcurrent < end) mb->current = newcurrent; else { grow_mallocbuf(mb, newcurrent - end + 1); - n = vsnprintf(mb->current, mb->buffer + mb->size - mb->current, fmt, ap); + va_list ap1; + va_copy(ap1, ap); + n = vsnprintf(mb->current, mb->buffer + mb->size - mb->current, fmt, ap1); + va_end(ap1); char *newcurrent = mb->current + n; char *end = mb->buffer + mb->size; if (newcurrent < end)