diff options
author | Daiki Ueno <dueno@redhat.com> | 2019-06-02 10:17:22 +0200 |
---|---|---|
committer | Daiki Ueno <ueno@gnu.org> | 2019-06-18 14:17:28 +0200 |
commit | bbb7f046ff430d33267487cb6f8a0e24d2eab832 (patch) | |
tree | 1bbafeb3e87085cdc51b0e346accb2372425ecb4 /common | |
parent | 5fc2d67b5ebb3daddb350d7ac60ede74dd99fcc6 (diff) |
common: Fix vasprintf emulation
va_list must be saved when calling vsnprintf() in a loop.
Diffstat (limited to 'common')
-rw-r--r-- | common/compat.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/common/compat.c b/common/compat.c index 5f47534..621f03a 100644 --- a/common/compat.c +++ b/common/compat.c @@ -570,6 +570,7 @@ vasprintf (char **strp, char *nbuf; int guess = 128; int length = 0; + va_list orig, aq; int ret; if (fmt == NULL) { @@ -577,17 +578,21 @@ vasprintf (char **strp, return -1; } + va_copy (orig, ap); for (;;) { nbuf = realloc (buf, guess); if (!nbuf) { free (buf); + va_end (orig); return -1; } buf = nbuf; length = guess; - ret = vsnprintf (buf, length, fmt, ap); + va_copy (aq, orig); + ret = vsnprintf (buf, length, fmt, aq); + va_end (aq); if (ret < 0) guess *= 2; @@ -598,6 +603,7 @@ vasprintf (char **strp, else break; } + va_end (orig); *strp = buf; return ret; |