summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorJuliusz Chroboczek <jch@pps.jussieu.fr>2008-05-11 00:46:52 +0200
committerJuliusz Chroboczek <jch@pps.jussieu.fr>2008-05-11 00:46:52 +0200
commitb3046750c37837dfe6d2a488361a1c78abdce138 (patch)
treec665631fbe39719dc0a1505432337e0bff71f9c0 /util.c
parenta0d110f283e387e9c594d422c5c75cb593def91e (diff)
Use va_copy in vsprintf_alloc.
This avoids a crash on arches with an interesting implementation of va_list (such as AMD64) but no vasprintf in their libc.
Diffstat (limited to 'util.c')
-rw-r--r--util.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/util.c b/util.c
index e4ca332..72ca9b9 100644
--- a/util.c
+++ b/util.c
@@ -92,19 +92,26 @@ vsprintf_alloc(char *f, va_list args)
return r;
}
#else
-/* This is not portable, doesn't do va_copy right. */
char*
vsprintf_alloc(char *f, va_list args)
{
int n, size = 12;
char *string;
+ va_list args_copy;
+
while(1) {
if(size > 4096)
return NULL;
string = malloc(size);
if(!string)
return NULL;
+
+#if HAVE_DECL_VA_COPY
+ va_copy(args_copy, args);
+ n = vsnprintf(string, size, f, args_copy);
+#else
n = vsnprintf(string, size, f, args);
+#endif
if(n >= 0 && n < size)
return string;
else if(n >= size)