svn commit: samba r21174 - in branches/SAMBA_4_0/source/lib: replace talloc util

tridge at samba.org tridge at samba.org
Tue Feb 6 05:26:26 GMT 2007


Author: tridge
Date: 2007-02-06 05:26:25 +0000 (Tue, 06 Feb 2007)
New Revision: 21174

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=21174

Log:

many thanks to Paul Wayper for pointing out that C99 requires a
matching va_end() for each va_copy(). This doesn't matter for most
architectures, but there could be some obscure ones where it does
matter.

some of this should be ported to Samba3

Modified:
   branches/SAMBA_4_0/source/lib/replace/snprintf.c
   branches/SAMBA_4_0/source/lib/talloc/talloc.c
   branches/SAMBA_4_0/source/lib/util/dprintf.c
   branches/SAMBA_4_0/source/lib/util/util_file.c
   branches/SAMBA_4_0/source/lib/util/xfile.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/replace/snprintf.c
===================================================================
--- branches/SAMBA_4_0/source/lib/replace/snprintf.c	2007-02-06 04:47:44 UTC (rev 21173)
+++ branches/SAMBA_4_0/source/lib/replace/snprintf.c	2007-02-06 05:26:25 UTC (rev 21174)
@@ -742,6 +742,8 @@
 	ret = currlen;
 
 done:
+	va_end(args);
+
 	while (chunks) {
 		cnk = chunks->next;
 		free(chunks);
@@ -1260,16 +1262,16 @@
 	va_list ap2;
 
 	VA_COPY(ap2, ap);
-	
 	ret = vsnprintf(NULL, 0, format, ap2);
+	va_end(ap2);
 	if (ret <= 0) return ret;
 
 	(*ptr) = (char *)malloc(ret+1);
 	if (!*ptr) return -1;
 
 	VA_COPY(ap2, ap);
-
 	ret = vsnprintf(*ptr, ret+1, format, ap2);
+	va_end(ap2);
 
 	return ret;
 }

Modified: branches/SAMBA_4_0/source/lib/talloc/talloc.c
===================================================================
--- branches/SAMBA_4_0/source/lib/talloc/talloc.c	2007-02-06 04:47:44 UTC (rev 21173)
+++ branches/SAMBA_4_0/source/lib/talloc/talloc.c	2007-02-06 05:26:25 UTC (rev 21174)
@@ -1174,10 +1174,11 @@
 	va_list ap2;
 	char c;
 	
+	/* this call looks strange, but it makes it work on older solaris boxes */
 	va_copy(ap2, ap);
-
-	/* this call looks strange, but it makes it work on older solaris boxes */
-	if ((len = vsnprintf(&c, 1, fmt, ap2)) < 0) {
+	len = vsnprintf(&c, 1, fmt, ap2);
+	va_end(ap2);
+	if (len < 0) {
 		return NULL;
 	}
 
@@ -1185,6 +1186,7 @@
 	if (ret) {
 		va_copy(ap2, ap);
 		vsnprintf(ret, len+1, fmt, ap2);
+		va_end(ap2);
 		_talloc_set_name_const(ret, ret);
 	}
 
@@ -1226,10 +1228,13 @@
 
 	tc = talloc_chunk_from_ptr(s);
 
+	s_len = tc->size - 1;
+
 	va_copy(ap2, ap);
+	len = vsnprintf(&c, 1, fmt, ap2);
+	va_end(ap2);
 
-	s_len = tc->size - 1;
-	if ((len = vsnprintf(&c, 1, fmt, ap2)) <= 0) {
+	if (len <= 0) {
 		/* Either the vsnprintf failed or the format resulted in
 		 * no characters being formatted. In the former case, we
 		 * ought to return NULL, in the latter we ought to return
@@ -1243,8 +1248,8 @@
 	if (!s) return NULL;
 
 	va_copy(ap2, ap);
-
 	vsnprintf(s+s_len, len+1, fmt, ap2);
+	va_end(ap2);
 	_talloc_set_name_const(s, s);
 
 	return s;

Modified: branches/SAMBA_4_0/source/lib/util/dprintf.c
===================================================================
--- branches/SAMBA_4_0/source/lib/util/dprintf.c	2007-02-06 04:47:44 UTC (rev 21173)
+++ branches/SAMBA_4_0/source/lib/util/dprintf.c	2007-02-06 05:26:25 UTC (rev 21174)
@@ -39,8 +39,8 @@
 
 	/* do any message translations */
 	va_copy(ap2, ap);
-
 	ret = vasprintf(&p, format, ap2);
+	va_end(ap2);
 
 	if (ret <= 0) return ret;
 

Modified: branches/SAMBA_4_0/source/lib/util/util_file.c
===================================================================
--- branches/SAMBA_4_0/source/lib/util/util_file.c	2007-02-06 04:47:44 UTC (rev 21173)
+++ branches/SAMBA_4_0/source/lib/util/util_file.c	2007-02-06 05:26:25 UTC (rev 21174)
@@ -364,8 +364,8 @@
 	va_list ap2;
 
 	va_copy(ap2, ap);
-
 	len = vasprintf(&p, format, ap2);
+	va_end(ap2);
 	if (len <= 0) return len;
 	ret = write(fd, p, len);
 	SAFE_FREE(p);

Modified: branches/SAMBA_4_0/source/lib/util/xfile.c
===================================================================
--- branches/SAMBA_4_0/source/lib/util/xfile.c	2007-02-06 04:47:44 UTC (rev 21173)
+++ branches/SAMBA_4_0/source/lib/util/xfile.c	2007-02-06 05:26:25 UTC (rev 21174)
@@ -203,8 +203,8 @@
 	va_list ap2;
 
 	va_copy(ap2, ap);
-
 	len = vasprintf(&p, format, ap2);
+	va_end(ap2);
 	if (len <= 0) return len;
 	ret = x_fwrite(p, 1, len, f);
 	SAFE_FREE(p);



More information about the samba-cvs mailing list