From e052d272e906c9e0961a447a43152b47190b2d03 Mon Sep 17 00:00:00 2001 From: Marko Stankovic Date: Mon, 13 Feb 2012 16:21:59 +0100 Subject: cesar/lib: fix left shift is negative warning, refs #2949 --- cesar/cp/msg/src/msg_drv.c | 2 +- cesar/lib/utils.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'cesar') diff --git a/cesar/cp/msg/src/msg_drv.c b/cesar/cp/msg/src/msg_drv.c index bbfd3523bf..bf4cfc9e1b 100644 --- a/cesar/cp/msg/src/msg_drv.c +++ b/cesar/cp/msg/src/msg_drv.c @@ -328,7 +328,7 @@ cp_msg_drv_sta_set_tonemask_req_receive (cp_t *ctx, cp_mme_rx_t *mme, /* Check last carriers are unused. */ if (PHY_CARRIER_NB % 32) { - w = tonemask[-1] | BITS_ONES (PHY_CARRIER_NB % 32); + w = tonemask[-1] | BITS_ONES_OR_ZERO (PHY_CARRIER_NB % 32); if (w != ~0u) return false; } diff --git a/cesar/lib/utils.h b/cesar/lib/utils.h index 306030ffff..c88c7fd03b 100644 --- a/cesar/lib/utils.h +++ b/cesar/lib/utils.h @@ -134,6 +134,17 @@ lesseq_mod2p16 (u16 a, u16 b) */ #define BITS_ONES(b) ((1u << ((b) - 1) << 1) - 1) +/** Return a bit mask composed of a number of LSB ones. + * \param b number of one bits, 0 to 32 + * + * - BITS_ONES_OR_ZERO (0) => 0x00000000 + * - BITS_ONES_OR_ZERO (1) => 0x00000001 + * - BITS_ONES_OR_ZERO (15) => 0x00007fff + * - BITS_ONES_OR_ZERO (32) => 0xffffffff + */ +#define BITS_ONES_OR_ZERO(b) ({ typeof (b) _b = (b);\ + _b ? ((1u << (_b - 1) << 1) - 1) : 0; }) + /** Return a bit mask composed of a number of LSB ones, corresponding to the * given bit field. * \param f bit field define -- cgit v1.2.3