diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-11-16 02:20:16 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-11-16 02:20:16 +0000 |
commit | 21a0359fab067eb9ab1808f268a4c9a1e08c8635 (patch) | |
tree | b3d64be02c95c7c681ddbe923a0e55a5b4aa3b5d /astmm.c | |
parent | e7e1a85da61dab679f0bf1a688e5be109f48d248 (diff) |
issue #5035
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@7110 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'astmm.c')
-rwxr-xr-x | astmm.c | 29 |
1 files changed, 14 insertions, 15 deletions
@@ -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[]) |