aboutsummaryrefslogtreecommitdiffstats
path: root/testing/tf/0002-Correct-use-of-va_list.patch
blob: d13fcd8542116aa5d5249cee7d8fef8b373aba20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
From: Russ Allbery <rra@debian.org>
Date: Sun, 17 Feb 2008 22:23:24 -0800
Subject: 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.
---
 src/tfio.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

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);