summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauri Kenttä <lauri.kentta@gmail.com>2015-05-10 13:40:29 +0300
committerNikita Popov <nikic@php.net>2015-05-10 13:00:45 +0200
commitcf7e5357a46afe1dca978f4887bbd83a7507ce69 (patch)
tree2692e6ba98c0748ee183e741d8286d671c646537
parent8c8889e7d470e0e20d2cab641c9833b4b3b8c6ac (diff)
downloadphp-git-cf7e5357a46afe1dca978f4887bbd83a7507ce69.tar.gz
random_int: Fix power of two check.
(x & ~x) is always 0. ((x & (~x + 1)) != x) works. ((x & (x - 1)) != 0) works too.
-rw-r--r--ext/standard/random.c2
1 files changed, 1 insertions, 1 deletions
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;