From 716fc4dddd592ab16cbde68451ac488ed4c06299 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 7 Apr 2014 10:48:57 -0700 Subject: [PATCH] Make implicit numeric lossy casts explicit (with comments). --- .../crypto_generichash/blake2/ref/generichash_blake2b.c | 6 ++++-- src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libsodium/crypto_generichash/blake2/ref/generichash_blake2b.c b/src/libsodium/crypto_generichash/blake2/ref/generichash_blake2b.c index da4a170c..70e07a59 100644 --- a/src/libsodium/crypto_generichash/blake2/ref/generichash_blake2b.c +++ b/src/libsodium/crypto_generichash/blake2/ref/generichash_blake2b.c @@ -56,7 +56,8 @@ crypto_generichash_blake2b_init(crypto_generichash_blake2b_state *state, if (blake2b_init(state, (uint8_t) outlen) != 0) { return -1; } - } else if (blake2b_init_key(state, (uint8_t) outlen, key, keylen) != 0) { + } else if (blake2b_init_key(state, (uint8_t) outlen, key, + (uint8_t) keylen /* Is cast from size_t to uint8_t safe here? */ ) != 0) { return -1; } return 0; @@ -81,7 +82,8 @@ crypto_generichash_blake2b_init_salt_personal(crypto_generichash_blake2b_state * return -1; } } else if (blake2b_init_key_salt_personal(state, - (uint8_t) outlen, key, keylen, + (uint8_t)outlen, key, + (uint8_t)keylen, /* Is cast from size_t to uint8_t safe here? */ salt, personal) != 0) { return -1; } diff --git a/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c b/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c index 304f4878..ff86c0b0 100644 --- a/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +++ b/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c @@ -169,7 +169,8 @@ randombytes_sysrandom_buf(void * const buf, const size_t size) abort(); } #else - if (! CryptGenRandom(stream.hcrypt_prov, size, (BYTE *) buf)) { + // Is cast from size_t to DWORD safe here? + if (! CryptGenRandom(stream.hcrypt_prov, (DWORD) size, (BYTE *) buf)) { abort(); } #endif