Skip to content

Commit

Permalink
Fix MSVC warning C4127 in HASH_BLOOM_TEST (#261)
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
Quuxplusone committed May 14, 2024
1 parent eeba196 commit 619fe95
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/uthash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
} \
} \
Expand Down Expand Up @@ -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)))
Expand All @@ -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

Expand Down

0 comments on commit 619fe95

Please sign in to comment.