From 619fe95ca4679249528f086536aadd0c469dbd99 Mon Sep 17 00:00:00 2001 From: Arthur O'Dwyer Date: Tue, 14 May 2024 09:50:30 -0400 Subject: [PATCH] Fix MSVC warning C4127 in HASH_BLOOM_TEST (#261) MSVC `-W4` gives "warning C4127: conditional expression is constant" for `if (1 != 0)`, but no warning for `if (1)`. Use the latter instead of the former. In fact, the comparison against zero should really be all the way down in `HASH_BLOOM_BITTEST`. No functional change intended. Thanks to @noodlecollie for the patch! --- src/uthash.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/uthash.h b/src/uthash.h index 68693bf..57c9eac 100644 --- a/src/uthash.h +++ b/src/uthash.h @@ -159,7 +159,7 @@ do { if (head) { \ unsigned _hf_bkt; \ HASH_TO_BKT(hashval, (head)->hh.tbl->num_buckets, _hf_bkt); \ - if (HASH_BLOOM_TEST((head)->hh.tbl, hashval) != 0) { \ + if (HASH_BLOOM_TEST((head)->hh.tbl, hashval)) { \ HASH_FIND_IN_BKT((head)->hh.tbl, hh, (head)->hh.tbl->buckets[ _hf_bkt ], keyptr, keylen, hashval, out); \ } \ } \ @@ -196,7 +196,7 @@ do { } while (0) #define HASH_BLOOM_BITSET(bv,idx) (bv[(idx)/8U] |= (1U << ((idx)%8U))) -#define HASH_BLOOM_BITTEST(bv,idx) (bv[(idx)/8U] & (1U << ((idx)%8U))) +#define HASH_BLOOM_BITTEST(bv,idx) ((bv[(idx)/8U] & (1U << ((idx)%8U))) != 0) #define HASH_BLOOM_ADD(tbl,hashv) \ HASH_BLOOM_BITSET((tbl)->bloom_bv, ((hashv) & (uint32_t)((1UL << (tbl)->bloom_nbits) - 1U))) @@ -208,7 +208,7 @@ do { #define HASH_BLOOM_MAKE(tbl,oomed) #define HASH_BLOOM_FREE(tbl) #define HASH_BLOOM_ADD(tbl,hashv) -#define HASH_BLOOM_TEST(tbl,hashv) (1) +#define HASH_BLOOM_TEST(tbl,hashv) 1 #define HASH_BLOOM_BYTELEN 0U #endif