wangyi-fudan / wyhash

The FASTEST QUALITY hash function, random number generators (PRNG) and hash map.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

implicit-conversion warning in wyhash32.h

snej opened this issue · comments

Compiling wyhash32.h with Clang on macOS 10.15, I get the following warning that a uint64_t is being implicitly cast to unsigned:

vendor/wyhash/wyhash32.h:21:80: error: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'unsigned int' [-Werror,-Wshorten-64-to-32]
  if(i>=4){ seed^=_wyr32(p); see1^=_wyr32(p+i-4); } else if (i) seed^=_wyr24(p,i);
                                                                      ~~~~~~   ^

The fix is to add a cast to unsigned in the call to _wyr24 at line 21:

  if(i>=4){ seed^=_wyr32(p); see1^=_wyr32(p+i-4); } else if (i) seed^=_wyr24(p,(unsigned)i);

(Apologies for not submitting a PR, but it didn't seem worth forking the repo just to make a trivial 1-line change.)

The same issue might be present in the other headers; this is the only one I've compiled.

Same thing in wyhash.h at line 89; can be fixed by adding the same (unsigned) cast:

      else if (_likely_(len)){ a=_wyr3(p,(unsigned)len); b=0; }

updated, thanks!