Skip to content

Commit 619fe95

Browse files
committed
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!
1 parent eeba196 commit 619fe95

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/uthash.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ do {
159159
if (head) { \
160160
unsigned _hf_bkt; \
161161
HASH_TO_BKT(hashval, (head)->hh.tbl->num_buckets, _hf_bkt); \
162-
if (HASH_BLOOM_TEST((head)->hh.tbl, hashval) != 0) { \
162+
if (HASH_BLOOM_TEST((head)->hh.tbl, hashval)) { \
163163
HASH_FIND_IN_BKT((head)->hh.tbl, hh, (head)->hh.tbl->buckets[ _hf_bkt ], keyptr, keylen, hashval, out); \
164164
} \
165165
} \
@@ -196,7 +196,7 @@ do {
196196
} while (0)
197197

198198
#define HASH_BLOOM_BITSET(bv,idx) (bv[(idx)/8U] |= (1U << ((idx)%8U)))
199-
#define HASH_BLOOM_BITTEST(bv,idx) (bv[(idx)/8U] & (1U << ((idx)%8U)))
199+
#define HASH_BLOOM_BITTEST(bv,idx) ((bv[(idx)/8U] & (1U << ((idx)%8U))) != 0)
200200

201201
#define HASH_BLOOM_ADD(tbl,hashv) \
202202
HASH_BLOOM_BITSET((tbl)->bloom_bv, ((hashv) & (uint32_t)((1UL << (tbl)->bloom_nbits) - 1U)))
@@ -208,7 +208,7 @@ do {
208208
#define HASH_BLOOM_MAKE(tbl,oomed)
209209
#define HASH_BLOOM_FREE(tbl)
210210
#define HASH_BLOOM_ADD(tbl,hashv)
211-
#define HASH_BLOOM_TEST(tbl,hashv) (1)
211+
#define HASH_BLOOM_TEST(tbl,hashv) 1
212212
#define HASH_BLOOM_BYTELEN 0U
213213
#endif
214214

0 commit comments

Comments
 (0)