[master] 85eeae6 Make the (v)bprintf() macros also check for negative return values.
Poul-Henning Kamp
phk at FreeBSD.org
Thu Sep 14 16:24:05 UTC 2017
commit 85eeae6b98f7a87000d5e85beb4f6d4bd55d6168
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