technion/libscrypt

Compiler warning about uint64_t to uint32_t downcast

uliwitness opened this issue · 2 comments

Hi, getting the following error when compiling with Xcode 6.1 (clang):

libscrypt/crypto_scrypt-check.c:84:14: warning: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
N = ipow(2, N);
~~~~ ^

N is declared as uint64_t. Is it OK to change the definition to uint32_t, or is there a reason why it's bigger?

There can't be a loss of precision because this call is directly preceded by a check on the size of N.

It's odd that GCC couldn't pick this comparison up even with -Wall -Wextra, and splint never complained about it. Perhaps they noted the forementioned check.

N is a uint64_t because that's the size used by the reference function, and I strictly wanted to neither change the reference function nor just put a cast there.

ipow() used a uint32_t because that matched the pow() function, but that's probably the better thing to fix. I'm committing a fix now.

Despite the commit typo about fixing 28, 3f4ed12 fixed this.