summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Allbery <rra@debian.org>2008-02-17 22:23:24 -0800
committerRuss Allbery <rra@debian.org>2018-05-26 19:03:58 -0700
commit56657bcd5a2fa61023bbaceec733caa65204bfbb (patch)
tree5194a2cfa6a140f98dfbbac00653829c6b43dee7
parent6a9f46f054976574b1fc316bc8468d9909f8b6ec (diff)
Correct use of va_list
va_copy a va_list before using it in vsprintf so that we don't use the same va_list repeatedly. Patch taken from the upstream bug tracker and will apparently be in the next release after 5.0beta8. Gbp-Pq: Name 0002-Correct-use-of-va_list.patch
-rw-r--r--src/tfio.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/tfio.c b/src/tfio.c
index 2cd2103..151583e 100644
--- a/src/tfio.c
+++ b/src/tfio.c
@@ -497,6 +497,7 @@ void vSprintf(String *buf, int flags, const char *fmt, va_list ap)
const conString *Sval;
int len, min, max, leftjust, stars;
attr_t attrs = buf->attrs;
+ va_list ap_copy;
if (!(flags & SP_APPEND) && buf->data) Stringtrunc(buf, 0);
while (*fmt) {
@@ -522,7 +523,9 @@ void vSprintf(String *buf, int flags, const char *fmt, va_list ap)
case 'x': case 'X': case 'u': case 'o':
case 'f': case 'e': case 'E': case 'g': case 'G':
case 'p':
- vsprintf(tempbuf, spec, ap);
+ va_copy(ap_copy, ap);
+ vsprintf(tempbuf, spec, ap_copy);
+ va_end(ap_copy);
Stringcat(buf, tempbuf);
/* eat the arguments used by vsprintf() */
while (stars--) (void)va_arg(ap, int);