From: Lauri Kenttä Date: Sun, 10 May 2015 10:40:29 +0000 (+0300) Subject: random_int: Fix power of two check. X-Git-Tag: PRE_PHP7_NSAPI_REMOVAL~53 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cf7e5357a46afe1dca978f4887bbd83a7507ce69;p=php random_int: Fix power of two check. (x & ~x) is always 0. ((x & (~x + 1)) != x) works. ((x & (x - 1)) != 0) works too. --- diff --git a/ext/standard/random.c b/ext/standard/random.c index 12c25031d8..4a1adbfb02 100644 --- a/ext/standard/random.c +++ b/ext/standard/random.c @@ -182,7 +182,7 @@ PHP_FUNCTION(random_int) umax++; /* Powers of two are not biased */ - if ((umax & ~umax) != umax) { + if ((umax & (umax - 1)) != 0) { /* Ceiling under which ZEND_LONG_MAX % max == 0 */ zend_ulong limit = ZEND_ULONG_MAX - (ZEND_ULONG_MAX % umax) - 1;