X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2Fmempool-fmt.c;h=b65789f54da6dcafd51b04f34f32b4bd595c28cb;hb=8ab69f51fccccbcae521bd7f7e3ae27146fd1217;hp=47bb71eb4a61c67eb8be7495a93b1fe3f578ef54;hpb=70398f11c811ae9acad63c31eec3611b2b7322d9;p=libucw.git diff --git a/lib/mempool-fmt.c b/lib/mempool-fmt.c index 47bb71eb..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; @@ -66,9 +73,9 @@ mp_printf(struct mempool *p, char *fmt, ...) int main(void) { struct mempool *mp = mp_new(64); - char *x = mp_printf(mp, "Hello, %s!\n", "World"); + char *x = mp_printf(mp, "", "World"); fputs(x, stdout); - x = mp_printf(mp, "Hello, %100s!\n", "World"); + x = mp_printf(mp, "\n", "World"); fputs(x, stdout); return 0; }