diff options
author | Juliusz Chroboczek <jch@pps.jussieu.fr> | 2008-05-11 00:46:52 +0200 |
---|---|---|
committer | Juliusz Chroboczek <jch@pps.jussieu.fr> | 2008-05-11 00:46:52 +0200 |
commit | b3046750c37837dfe6d2a488361a1c78abdce138 (patch) | |
tree | c665631fbe39719dc0a1505432337e0bff71f9c0 /util.c | |
parent | a0d110f283e387e9c594d422c5c75cb593def91e (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.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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) |