Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.

Fixed issue with Math\Rand::getInteger() on ranges close to PHP_INT_MAX#5614

Merged
ezimuel merged 3 commits into
zendframework:masterfrom
denixport:hotfix/rand-int
Mar 5, 2014
Merged

Fixed issue with Math\Rand::getInteger() on ranges close to PHP_INT_MAX#5614
ezimuel merged 3 commits into
zendframework:masterfrom
denixport:hotfix/rand-int

Conversation

@denixport
Copy link
Copy Markdown
Contributor

When min - max range is close or equal to PHP_INT_MAX log() produces number of bits
equal to machine size integer. So $filter = (int) ((1 << $bits) - 1); evaluates to zero.
In this case getInteger(0, PHP_INT_MAX) returns only zeros.

PR includes correct bit calculation and test

Comment thread library/Zend/Math/Rand.php Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use static::getBytes instead of self::getBytes

@denixport
Copy link
Copy Markdown
Contributor Author

@samsonasik @ezimuel PTAL

@weierophinney weierophinney added this to the 2.2.6 milestone Mar 3, 2014
@ezimuel ezimuel merged commit cc11994 into zendframework:master Mar 5, 2014
@Maks3w
Copy link
Copy Markdown
Member

Maks3w commented May 1, 2015

Is it normal $values to be negative?

I've changed the test for assert $values to be greater than 0

1) ZendTest\Math\RandTest::testIntegerRangeOverflow
Failed asserting that -5.1650883406387E+20 is greater than 0.

https://travis-ci.org/zendframework/zf2/jobs/60848303#L1081

@Maks3w
Copy link
Copy Markdown
Member

Maks3w commented May 1, 2015

Ok, I see what is happenning. $values probably has a value which produce a int overflow as result of operate with big numbers.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants