From 07921d07fe941ceb16364e5b610993a7096604c3 Mon Sep 17 00:00:00 2001 From: David Wragg Date: Thu, 28 Oct 2010 08:12:15 +0100 Subject: Fix a bug in the asprintf implementation *strp[len] does not mean (*strp)[len] --- tools/windows/compat.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/windows/compat.c b/tools/windows/compat.c index f0508b2..bce318b 100644 --- a/tools/windows/compat.c +++ b/tools/windows/compat.c @@ -61,13 +61,16 @@ int asprintf(char **strp, const char *fmt, ...) va_start(ap, fmt); len = _vscprintf(fmt, ap); + va_end(ap); + *strp = malloc(len+1); if (!*strp) return -1; - len = vsprintf(*strp, fmt, ap); - *strp[len] = 0; - + va_start(ap, fmt); + _vsnprintf(*strp, len+1, fmt, ap); va_end(ap); + + (*strp)[len] = 0; return len; } -- cgit v1.2.1