From a31a587bc0d6115a241fcc523bc76b3de0f3dc0d Mon Sep 17 00:00:00 2001 From: "Kevin P. Fleming" Date: Wed, 16 Nov 2005 02:20:16 +0000 Subject: issue #5035 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7110 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- astmm.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'astmm.c') diff --git a/astmm.c b/astmm.c index d1692de27..3f94e05fa 100755 --- a/astmm.c +++ b/astmm.c @@ -254,21 +254,20 @@ char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const int __ast_vasprintf(char **strp, const char *fmt, va_list ap, const char *file, int lineno, const char *func) { - int n, size = strlen(fmt) + 1; - if ((*strp = __ast_alloc_region(size, FUNC_VASPRINTF, file, lineno, func)) == NULL) - return -1; - for (;;) { - n = vsnprintf(*strp, size, fmt, ap); - if (n > -1 && n < size) - return n; - if (n > -1) { /* glibc 2.1 */ - size = n+1; - } else { /* glibc 2.0 */ - size *= 2; - } - if ((*strp = __ast_realloc(*strp, size, file, lineno, func)) == NULL) - return -1; - } + int size; + va_list ap2; + char s; + + *strp = NULL; + va_copy(ap2, ap); + size = vsnprintf(&s, 1, fmt, ap2); + va_end(ap2); + *strp = __ast_alloc_region(size + 1, FUNC_VASPRINTF, file, lineno, func); + if (!*strp) + return -1; + vsnprintf(*strp, size + 1, fmt, ap); + + return size; } static int handle_show_memory(int fd, int argc, char *argv[]) -- cgit v1.2.3