From 82d2958ef98253fae000d193c792fef9f453c7e0 Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Sat, 13 Oct 2018 21:47:27 -0400 Subject: [PATCH] ck_epoch: add compile-time checks for CK_EPOCH_LENGTH validity. This work is from jtl@FreeBSD.org. --- src/ck_epoch.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ck_epoch.c b/src/ck_epoch.c index 146e4ce..114ff62 100644 --- a/src/ck_epoch.c +++ b/src/ck_epoch.c @@ -127,6 +127,14 @@ */ #define CK_EPOCH_GRACE 3U +/* + * CK_EPOCH_LENGTH must be a power-of-2 (because (CK_EPOCH_LENGTH - 1) is used + * as a mask, and it must be at least 3 (see comments above). + */ +#if (CK_EPOCH_LENGTH < 3 || (CK_EPOCH_LENGTH & (CK_EPOCH_LENGTH - 1)) != 0) +#error "CK_EPOCH_LENGTH must be a power of 2 and >= 3" +#endif + enum { CK_EPOCH_STATE_USED = 0, CK_EPOCH_STATE_FREE = 1