mirror of
https://github.com/php/php-src.git
synced 2024-09-22 10:27:25 +00:00
random_int: Fix power of two check.
(x & ~x) is always 0. ((x & (~x + 1)) != x) works. ((x & (x - 1)) != 0) works too.
This commit is contained in:
parent
8c8889e7d4
commit
cf7e5357a4
@ -182,7 +182,7 @@ PHP_FUNCTION(random_int)
|
|||||||
umax++;
|
umax++;
|
||||||
|
|
||||||
/* Powers of two are not biased */
|
/* Powers of two are not biased */
|
||||||
if ((umax & ~umax) != umax) {
|
if ((umax & (umax - 1)) != 0) {
|
||||||
/* Ceiling under which ZEND_LONG_MAX % max == 0 */
|
/* Ceiling under which ZEND_LONG_MAX % max == 0 */
|
||||||
zend_ulong limit = ZEND_ULONG_MAX - (ZEND_ULONG_MAX % umax) - 1;
|
zend_ulong limit = ZEND_ULONG_MAX - (ZEND_ULONG_MAX % umax) - 1;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user