Fix use of va_copy() in logging functions

This commit is contained in:
Andrew Bettison 2018-05-07 23:25:58 +09:30
parent b8b31ed97a
commit 98fa034c53
2 changed files with 13 additions and 7 deletions

10
log.c
View File

@ -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;
}

View File

@ -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)