diff options
author | David Wragg <david@rabbitmq.com> | 2010-10-28 08:12:15 +0100 |
---|---|---|
committer | David Wragg <david@rabbitmq.com> | 2010-10-28 08:12:15 +0100 |
commit | 07921d07fe941ceb16364e5b610993a7096604c3 (patch) | |
tree | ba394ec699834f44414a76f2b51781aff5f5dba5 | |
parent | 21ef8798cf7149bc3f16162f5286cf0f142f5b08 (diff) | |
download | rabbitmq-c-github-ask-07921d07fe941ceb16364e5b610993a7096604c3.tar.gz |
Fix a bug in the asprintf implementation
*strp[len] does not mean (*strp)[len]
-rw-r--r-- | tools/windows/compat.c | 9 |
1 files changed, 6 insertions, 3 deletions
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; } |