summaryrefslogtreecommitdiffstats
path: root/source3/lib/snprintf.c
diff options
context:
space:
mode:
authorJim McDonough <jmcd@samba.org>2002-05-17 14:51:22 +0000
committerJim McDonough <jmcd@samba.org>2002-05-17 14:51:22 +0000
commitc7523c57512258007f0ac5271697fc6a9f4618d6 (patch)
tree43ab98ce3e97f2a910c15ef76978bb46a8471407 /source3/lib/snprintf.c
parent31cda568c05624ef5e7fd2970c5f2733e67eedc3 (diff)
downloadsamba-c7523c57512258007f0ac5271697fc6a9f4618d6.tar.gz
samba-c7523c57512258007f0ac5271697fc6a9f4618d6.tar.xz
samba-c7523c57512258007f0ac5271697fc6a9f4618d6.zip
Fix usage of va_list passed as an arg. Use __va_copy before using it
when it exists. (This used to be commit 85ab07bdc1b2ce7b2c1b8197fad45124b1460dca)
Diffstat (limited to 'source3/lib/snprintf.c')
-rw-r--r--source3/lib/snprintf.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/source3/lib/snprintf.c b/source3/lib/snprintf.c
index ee0d302b0f..561e775c8f 100644
--- a/source3/lib/snprintf.c
+++ b/source3/lib/snprintf.c
@@ -106,7 +106,7 @@
#endif
static size_t dopr(char *buffer, size_t maxlen, const char *format,
- va_list args);
+ va_list args_in);
static void fmtstr(char *buffer, size_t *currlen, size_t maxlen,
char *value, int flags, int min, int max);
static void fmtint(char *buffer, size_t *currlen, size_t maxlen,
@@ -149,7 +149,7 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c);
#define MAX(p,q) (((p) >= (q)) ? (p) : (q))
#endif
-static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args)
+static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args_in)
{
char ch;
LLONG value;
@@ -161,6 +161,13 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
int flags;
int cflags;
size_t currlen;
+ va_list args;
+
+#if defined(HAVE_VA_COPY)
+ __va_copy(args, args_in);
+#else
+ args = args_in;
+#endif
state = DP_S_DEFAULT;
currlen = flags = cflags = min = 0;
@@ -793,13 +800,23 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c)
int vasprintf(char **ptr, const char *format, va_list ap)
{
int ret;
+ va_list ap2;
+
+#if defined(HAVE_VA_COPY)
+ __va_copy(ap2, ap);
+#else
+ ap2 = ap;
+#endif
- ret = vsnprintf(NULL, 0, format, ap);
+ ret = vsnprintf(NULL, 0, format, ap2);
if (ret <= 0) return ret;
(*ptr) = (char *)malloc(ret+1);
if (!*ptr) return -1;
- ret = vsnprintf(*ptr, ret+1, format, ap);
+#if defined(HAVE_VA_COPY)
+ __va_copy(ap2, ap);
+#endif
+ ret = vsnprintf(*ptr, ret+1, format, ap2);
return ret;
}