r4458 - trunk/varnish-cache/include

phk at projects.linpro.no phk at projects.linpro.no
Thu Jan 14 12:58:48 CET 2010


Author: phk
Date: 2010-01-14 12:58:48 +0100 (Thu, 14 Jan 2010)
New Revision: 4458

Modified:
   trunk/varnish-cache/include/libvarnish.h
Log:
Add a couple of macros for safely (assertedly) printing into a
static sized buffer.



Modified: trunk/varnish-cache/include/libvarnish.h
===================================================================
--- trunk/varnish-cache/include/libvarnish.h	2010-01-14 10:01:07 UTC (rev 4457)
+++ trunk/varnish-cache/include/libvarnish.h	2010-01-14 11:58:48 UTC (rev 4458)
@@ -133,3 +133,17 @@
 	abort();							\
 } while (0)
 const char* svn_version(void);
+
+/* Safe printf into a fixed-size buffer */
+#define bprintf(buf, fmt, ...)						\
+	do {								\
+		assert(snprintf(buf, sizeof buf, fmt, __VA_ARGS__)	\
+		    < sizeof buf);					\
+	} while (0)
+
+/* Safe printf into a fixed-size buffer */
+#define vbprintf(buf, fmt, ap)						\
+	do {								\
+		assert(vsnprintf(buf, sizeof buf, fmt, ap)		\
+		    < sizeof buf);					\
+	} while (0)



More information about the varnish-commit mailing list