mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
random/standard: Adjust #13138 for PHP 8.3
This commit is contained in:
@@ -61,6 +61,18 @@ try {
|
||||
echo $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump(randomizer()->getBytesFromString('123', 10));
|
||||
} catch (Random\BrokenRandomEngineError $e) {
|
||||
echo $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump(randomizer()->getBytesFromString(str_repeat('a', 500), 10));
|
||||
} catch (Random\BrokenRandomEngineError $e) {
|
||||
echo $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
int(0)
|
||||
@@ -320,3 +332,5 @@ array(1) {
|
||||
}
|
||||
Failed to generate an acceptable random number in 50 attempts
|
||||
string(6) "oobarf"
|
||||
string(10) "1111111111"
|
||||
string(10) "aaaaaaaaaa"
|
||||
|
||||
@@ -6179,10 +6179,9 @@ PHPAPI bool php_array_pick_keys(const php_random_algo *algo, php_random_status *
|
||||
goto fail;
|
||||
}
|
||||
if (zend_bitset_in(bitset, randval)) {
|
||||
/* Use PHP_RANDOM_RANGE_ATTEMPTS instead of the hardcoded 50 for 8.3+. */
|
||||
if (++failures > 50) {
|
||||
if (++failures > PHP_RANDOM_RANGE_ATTEMPTS) {
|
||||
if (!silent) {
|
||||
zend_throw_error(random_ce_Random_BrokenRandomEngineError, "Failed to generate an acceptable random number in %d attempts", 50);
|
||||
zend_throw_error(random_ce_Random_BrokenRandomEngineError, "Failed to generate an acceptable random number in %d attempts", PHP_RANDOM_RANGE_ATTEMPTS);
|
||||
}
|
||||
|
||||
goto fail;
|
||||
|
||||
Reference in New Issue
Block a user