svn commit: samba r13397 - in branches/SAMBA_4_0/source/lib/talloc: .

jpeach at samba.org jpeach at samba.org
Wed Feb 8 23:44:17 GMT 2006


Author: jpeach
Date: 2006-02-08 23:44:17 +0000 (Wed, 08 Feb 2006)
New Revision: 13397

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

Log:
Propagate the error return from vsnprintf to trap the case where
we aren't linked against a C99 vsnprintf.

Modified:
   branches/SAMBA_4_0/source/lib/talloc/talloc.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/talloc/talloc.c
===================================================================
--- branches/SAMBA_4_0/source/lib/talloc/talloc.c	2006-02-08 22:16:03 UTC (rev 13396)
+++ branches/SAMBA_4_0/source/lib/talloc/talloc.c	2006-02-08 23:44:17 UTC (rev 13397)
@@ -1011,7 +1011,9 @@
 	
 	VA_COPY(ap2, ap);
 
-	len = vsnprintf(NULL, 0, fmt, ap2);
+	if ((len = vsnprintf(NULL, 0, fmt, ap2)) <= 0) {
+		return NULL;
+	}
 
 	ret = _talloc(t, len+1);
 	if (ret) {
@@ -1060,7 +1062,15 @@
 	VA_COPY(ap2, ap);
 
 	s_len = tc->size - 1;
-	len = vsnprintf(NULL, 0, fmt, ap2);
+	if ((len = vsnprintf(NULL, 0, fmt, ap2)) <= 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
+		 * the original string. Most current callers of this 
+		 * function expect it to never return NULL.
+		 */
+		return s;
+	}
 
 	s = talloc_realloc(NULL, s, char, s_len + len+1);
 	if (!s) return NULL;



More information about the samba-cvs mailing list