mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
PcgOneseq128XslRr64::jump(): Throw ValueError for negative $advance (#9213)
* PCG64: $advance must be non-negative Closes GH-9212
This commit is contained in:
parent
fac37347ce
commit
50bd8ba51c
@ -186,6 +186,11 @@ PHP_METHOD(Random_Engine_PcgOneseq128XslRr64, jump)
|
||||
Z_PARAM_LONG(advance);
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
if (UNEXPECTED(advance < 0)) {
|
||||
zend_argument_value_error(1, "must be greater than or equal to 0");
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
php_random_pcgoneseq128xslrr64_advance(state, advance);
|
||||
}
|
||||
/* }}} */
|
||||
|
@ -0,0 +1,23 @@
|
||||
--TEST--
|
||||
Random: Engine: PcgOneseq128XslRr64: Jump with negative $advance
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$engine = new \Random\Engine\PcgOneseq128XslRr64(1234);
|
||||
$referenceEngine = new \Random\Engine\PcgOneseq128XslRr64(1234);
|
||||
|
||||
try {
|
||||
$engine->jump(-1);
|
||||
} catch (ValueError $e) {
|
||||
echo $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
if ($engine->generate() !== $referenceEngine->generate()) {
|
||||
die('failure: state changed');
|
||||
}
|
||||
|
||||
die('success');
|
||||
?>
|
||||
--EXPECT--
|
||||
Random\Engine\PcgOneseq128XslRr64::jump(): Argument #1 ($advance) must be greater than or equal to 0
|
||||
success
|
Loading…
Reference in New Issue
Block a user