Skip to content

Commit

Permalink
uthash.h: Swap multiplicands to put the widest ones first.
Browse files Browse the repository at this point in the history
It was reported in troydhanson#195 that Visual Studio 2019, on a 32-bit platform,
produces this warning:

    Warning C26451
    Arithmetic overflow: Using operator '*' on a 4 byte value
    and then casting the result to a 8 byte value. Cast the
    value to the wider type before calling operator '*' to
    avoid overflow (io.2).

I'm not 100% sure that this tweak will silence the warning,
but I think it might, and at least it's harmless.

Fixes troydhanson#195.
  • Loading branch information
Quuxplusone committed Dec 8, 2020
1 parent 15ad042 commit 973bd67
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/uthash.h
Original file line number Diff line number Diff line change
Expand Up @@ -843,12 +843,12 @@ do {
struct UT_hash_handle *_he_thh, *_he_hh_nxt; \
UT_hash_bucket *_he_new_buckets, *_he_newbkt; \
_he_new_buckets = (UT_hash_bucket*)uthash_malloc( \
2UL * (tbl)->num_buckets * sizeof(struct UT_hash_bucket)); \
sizeof(struct UT_hash_bucket) * (tbl)->num_buckets * 2U); \
if (!_he_new_buckets) { \
HASH_RECORD_OOM(oomed); \
} else { \
uthash_bzero(_he_new_buckets, \
2UL * (tbl)->num_buckets * sizeof(struct UT_hash_bucket)); \
sizeof(struct UT_hash_bucket) * (tbl)->num_buckets * 2U); \
(tbl)->ideal_chain_maxlen = \
((tbl)->num_items >> ((tbl)->log2_num_buckets+1U)) + \
((((tbl)->num_items & (((tbl)->num_buckets*2U)-1U)) != 0U) ? 1U : 0U); \
Expand Down

0 comments on commit 973bd67

Please sign in to comment.