[5.2] 55dab8e Make the (v)bprintf() macros also check for negative return values.
PÃ¥l Hermunn Johansen
hermunn at varnish-software.com
Fri Sep 15 11:17:30 UTC 2017
commit 55dab8e8ae39f0ac85cb3c48ddefc8f948087dfe
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Sep 14 16:22:35 2017 +0000
Make the (v)bprintf() macros also check for negative return values.
diff --git a/include/vdef.h b/include/vdef.h
index af51c47..b7fee8b 100644
--- a/include/vdef.h
+++ b/include/vdef.h
@@ -38,15 +38,17 @@
/* Safe printf into a fixed-size buffer */
#define bprintf(buf, fmt, ...) \
do { \
- assert(snprintf(buf, sizeof buf, fmt, __VA_ARGS__) \
- < sizeof buf); \
+ int ibprintf; \
+ ibprintf = snprintf(buf, sizeof buf, fmt, __VA_ARGS__); \
+ assert(ibprintf >= 0 && ibprintf < 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); \
+ int ivbprintf; \
+ ivbprintf = vsnprintf(buf, sizeof buf, fmt, ap); \
+ assert(ivbprintf >= 0 && ivbprintf < sizeof buf); \
} while (0)
/* Close and discard filedescriptor */
More information about the varnish-commit
mailing list