changeset 126:7b22987a7b47

Vladimir Oleynik pointed out that va_start() twice in the same function isn't portable (with ppc 4xx as an example of a platform it doesn't work on). This is why va_copy exists.
author Rob Landley <rob@landley.net>
date Fri, 15 Jun 2007 15:16:46 -0400
parents a4af344fb349
children 343117774a9f
files lib/lib.c
diffstat 1 files changed, 6 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lib/lib.c	Thu Jun 07 15:20:26 2007 -0400
+++ b/lib/lib.c	Fri Jun 15 15:16:46 2007 -0400
@@ -126,22 +126,22 @@
 // Die unless we can allocate enough space to sprintf() into.
 char *xmsprintf(char *format, ...)
 {
-	va_list va;
+	va_list va, va2;
 	int len;
 	char *ret;
 	
-	// How long is it?
+	va_start(va, format);
+	va_copy(va2, va);
 
-	va_start(va, format);
+	// How long is it?
 	len = vsnprintf(0, 0, format, va);
 	len++;
 	va_end(va);
 
 	// Allocate and do the sprintf()
 	ret = xmalloc(len);
-	va_start(va, format);
-	vsnprintf(ret, len, format, va);	
-	va_end(va);
+	vsnprintf(ret, len, format, va2);	
+	va_end(va2);
 
 	return ret;
 }