com php-src: random_int: Fix power of two check .: ext/standard/random.c
| From: | Nikita Popov | Date: | Sun, 10 May 2015 11:00:45 +0000 |
| Subject: | com php-src: random_int: Fix power of two check .: ext/standard/random.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-86661@lists.php.net to get a copy of this message | ||
Commit: cf7e5357a46afe1dca978f4887bbd83a7507ce69
Author: Lauri Kenttä <lauri.kentta@gmail.com> Sun, 10 May 2015 13:40:29 +0300
Committer: Nikita Popov <nikic@php.net> Sun, 10 May 2015 13:00:45 +0200
Parents: 8c8889e7d470e0e20d2cab641c9833b4b3b8c6ac
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=cf7e5357a46afe1dca978f4887bbd83a7507ce69
Log:
random_int: Fix power of two check.
(x & ~x) is always 0.
((x & (~x + 1)) != x) works.
((x & (x - 1)) != 0) works too.
Changed paths:
M ext/standard/random.c
Diff:
diff --git a/ext/standard/random.c b/ext/standard/random.c
index 12c2503..4a1adbf 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;