From: Martin Mares Date: Wed, 14 Sep 2005 09:46:46 +0000 (+0000) Subject: Checked and corrected all uses of va_args. X-Git-Tag: holmes-import~741 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=01a353ec6f528d5320b5f5ac17ee80d37ed901bf;p=libucw.git Checked and corrected all uses of va_args. --- diff --git a/lib/ff-printf.c b/lib/ff-printf.c index aff49eb2..769f830e 100644 --- a/lib/ff-printf.c +++ b/lib/ff-printf.c @@ -1,7 +1,7 @@ /* * UCW Library -- Printf on Fastbuf Streams * - * (c) 2002 Martin Mares + * (c) 2002--2005 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -24,6 +24,7 @@ vbprintf(struct fastbuf *b, char *msg, va_list args) { va_copy(args2, args); r = vsnprintf(buf, len, msg, args2); + va_end(args2); if (r < 0) len = 256; else if (r < len) @@ -42,6 +43,7 @@ vbprintf(struct fastbuf *b, char *msg, va_list args) buf = alloca(len); va_copy(args2, args); r = vsnprintf(buf, len, msg, args2); + va_end(args2); if (r < 0) len += len; else if (r < len) diff --git a/lib/log.c b/lib/log.c index 45235ce9..88360004 100644 --- a/lib/log.c +++ b/lib/log.c @@ -1,7 +1,7 @@ /* * UCW Library -- Logging * - * (c) 1997--2004 Martin Mares + * (c) 1997--2005 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -31,6 +31,7 @@ vlog_msg(unsigned int cat, const char *msg, va_list args) byte *buf, *p; int buflen = 256; int l, l0, r; + va_list args2; if (log_switch_hook) log_switch_hook(tm); @@ -53,7 +54,9 @@ vlog_msg(unsigned int cat, const char *msg, va_list args) } l0 = p - buf + 1; r = buflen - l0; - l = vsnprintf(p, r, msg, args); + va_copy(args2, args); + l = vsnprintf(p, r, msg, args2); + va_end(args2); if (l < 0) l = r; else if (l < r) diff --git a/lib/mempool-fmt.c b/lib/mempool-fmt.c index c8b1e4c8..b65789f5 100644 --- a/lib/mempool-fmt.c +++ b/lib/mempool-fmt.c @@ -24,7 +24,10 @@ mp_vprintf(struct mempool *p, char *fmt, va_list args) ret = mp_alloc(p, 1); free = p->last - p->free; } - int cnt = vsnprintf(ret, free, fmt, args); + va_list args2; + va_copy(args2, args); + int cnt = vsnprintf(ret, free, fmt, args2); + va_end(args2); if (cnt < 0) { /* Our C library doesn't support C99 return value of vsnprintf, so we need to iterate */ @@ -34,7 +37,9 @@ mp_vprintf(struct mempool *p, char *fmt, va_list args) { len *= 2; buf = alloca(len); - cnt = vsnprintf(buf, len, fmt, args); + va_copy(args2, args); + cnt = vsnprintf(buf, len, fmt, args2); + va_end(args2); } while (cnt < 0); ret = mp_alloc(p, cnt+1); @@ -45,7 +50,9 @@ mp_vprintf(struct mempool *p, char *fmt, va_list args) else { ret = mp_alloc(p, cnt+1); - int cnt2 = vsnprintf(ret, cnt+1, fmt, args); + va_copy(args2, args); + int cnt2 = vsnprintf(ret, cnt+1, fmt, args2); + va_end(args2); ASSERT(cnt2 == cnt); } return ret; diff --git a/lib/runcmd.c b/lib/runcmd.c index dbb3c8a7..7f373877 100644 --- a/lib/runcmd.c +++ b/lib/runcmd.c @@ -24,12 +24,14 @@ exec_command_v(byte *cmd, va_list args) byte *arg; while (arg = va_arg(cargs, byte *)) cnt++; + va_end(cargs); char **argv = alloca(sizeof(byte *) * cnt); argv[0] = cmd; cnt = 1; va_copy(cargs, args); while (arg = va_arg(cargs, byte *)) argv[cnt++] = arg; + va_end(cargs); argv[cnt] = NULL; execv(cmd, argv); byte echo[256]; @@ -73,8 +75,6 @@ echo_command_v(byte *buf, int size, byte *cmd, va_list args) byte *limit = buf + size - 4; byte *p = buf; byte *arg = cmd; - va_list cargs; - va_copy(cargs, args); do { int l = strlen(arg); @@ -89,7 +89,7 @@ echo_command_v(byte *buf, int size, byte *cmd, va_list args) memcpy(p, arg, l); p += l; } - while (arg = va_arg(cargs, byte *)); + while (arg = va_arg(args, byte *)); *p = 0; } diff --git a/lib/stkstring.c b/lib/stkstring.c index a8593215..c7ac9ef5 100644 --- a/lib/stkstring.c +++ b/lib/stkstring.c @@ -31,7 +31,7 @@ static int stk_printf_len; uns stk_printf_internal(char *fmt, ...) { - va_list args; + va_list args, args2; va_start(args, fmt); if (!stk_printf_buf) { @@ -40,11 +40,16 @@ stk_printf_internal(char *fmt, ...) } for (;;) { - int l = vsnprintf(stk_printf_buf, stk_printf_len, fmt, args); + va_copy(args2, args); + int l = vsnprintf(stk_printf_buf, stk_printf_len, fmt, args2); + va_end(args2); if (l < 0) stk_printf_len *= 2; else if (l < stk_printf_len) - return l+1; + { + va_end(args); + return l+1; + } else stk_printf_len = MAX(stk_printf_len*2, l+1); stk_printf_buf = xrealloc(stk_printf_buf, stk_printf_len);