Remove ->last_unsafe from php_random_status (#9132)

Whenever ->last_unsafe is set to `true` an exception has been thrown. Thus we
can replace the check for `->last_unsafe` with a check for `EG(exception)`
which is a much more natural way to ommunicate an error up the chain.
This commit is contained in:
Tim Düsterhus 2022-07-26 09:02:51 +02:00 committed by GitHub
parent 60cae26be7
commit 5c693c770a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 13 additions and 24 deletions

View file

@ -105,7 +105,7 @@ PHP_METHOD(Random_Randomizer, getInt)
zend_throw_exception(spl_ce_RuntimeException, "Generated value exceeds size of int", 0);
RETURN_THROWS();
}
if (randomizer->status->last_unsafe) {
if (EG(exception)) {
zend_throw_exception(spl_ce_RuntimeException, "Random number generation failed", 0);
RETURN_THROWS();
}
@ -123,7 +123,7 @@ PHP_METHOD(Random_Randomizer, getInt)
}
result = randomizer->algo->range(randomizer->status, min, max);
if (randomizer->status->last_unsafe) {
if (EG(exception)) {
zend_throw_exception(spl_ce_RuntimeException, "Random number generation failed", 0);
RETURN_THROWS();
}
@ -155,7 +155,7 @@ PHP_METHOD(Random_Randomizer, getBytes)
while (total_size < required_size) {
result = randomizer->algo->generate(randomizer->status);
if (randomizer->status->last_unsafe) {
if (EG(exception)) {
zend_string_free(retval);
zend_throw_exception(spl_ce_RuntimeException, "Random number generation failed", 0);
RETURN_THROWS();