From f5673c7cc06db7f252ff3e787c987fa5fae627e9 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Mon, 20 Feb 2017 21:12:33 +0100 Subject: [PATCH] Avoid negating unsigned values --- src/libsodium/randombytes/randombytes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsodium/randombytes/randombytes.c b/src/libsodium/randombytes/randombytes.c index 20c063ec..a40b78e1 100644 --- a/src/libsodium/randombytes/randombytes.c +++ b/src/libsodium/randombytes/randombytes.c @@ -140,7 +140,7 @@ randombytes_uniform(const uint32_t upper_bound) if (upper_bound < 2) { return 0; } - min = (uint32_t) (-upper_bound % upper_bound); + min = (1U + ~upper_bound) % upper_bound; do { r = randombytes_random(); } while (r < min);