]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: switch i_rand_limit() - Replace signed expression with UNSIGNED_MINUS()
authorMarco Bettini <marco.bettini@open-xchange.com>
Fri, 26 Nov 2021 14:48:04 +0000 (15:48 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 30 Nov 2021 10:03:03 +0000 (10:03 +0000)
Found by code analysis tool

src/lib/rand.c

index 69f769a9ad96eeda5d0e870396c923143695b5da..12c9686b604952863a0a29c1b064bd20bf8728d2 100644 (file)
@@ -94,7 +94,7 @@ uint32_t i_rand_limit(uint32_t upper_bound)
        i_assert(upper_bound > 0);
 
        uint32_t val;
-       uint32_t min = ~(upper_bound - 1) % upper_bound;
+       uint32_t min = UNSIGNED_MINUS(upper_bound) % upper_bound;
        while((val = i_rand()) < min);
        return val % upper_bound;
 }