[master] 429966c Cast y argument to uintmax_t in RDN2/RUP2
Martin Blix Grydeland
martin at varnish-software.com
Thu Sep 25 15:02:28 CEST 2014
commit 429966cd9a7b9f36068589d87cef013b539740ad
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Wed Sep 24 17:07:07 2014 +0200
Cast y argument to uintmax_t in RDN2/RUP2
If the type of the y argument to RDN2/RUP2 is smaller than the type of
the x argument, these macros would fail to round correctly. Cast to
uintmax_t to avoid this problem.
diff --git a/bin/varnishd/common/common.h b/bin/varnishd/common/common.h
index 17b68b1..8295394 100644
--- a/bin/varnishd/common/common.h
+++ b/bin/varnishd/common/common.h
@@ -128,8 +128,8 @@ void VSM_common_ageupdate(struct vsm_sc *sc);
*/
#define PWR2(x) ((((x)-1)&(x))==0) /* Is a power of two */
-#define RDN2(x, y) ((x)&(~((y)-1))) /* if y is powers of two */
-#define RUP2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
+#define RDN2(x, y) ((x)&(~((uintmax_t)(y)-1))) /* PWR2(y) true */
+#define RUP2(x, y) (((x)+((y)-1))&(~((uintmax_t)(y)-1))) /* PWR2(y) true */
/*--------------------------------------------------------------------
* Pointer aligment magic
More information about the varnish-commit
mailing list