Remove superfluous helper variable in Randomizer::getBytes() (#9563)

* Remove superfluous helper variable in Randomizer::getBytes()

* Reduce the scope of `result` in Randomizer::getBytes()

Co-authored-by: Tim Düsterhus <tim@bastelstu.be>
This commit is contained in:
Joshua Rüsweg 2022-09-20 16:41:31 +01:00 committed by GitHub
parent 28a4d7676a
commit ca399841ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -141,8 +141,7 @@ PHP_METHOD(Random_Randomizer, getBytes)
php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
zend_string *retval;
zend_long length;
uint64_t result;
size_t total_size = 0, required_size;
size_t total_size = 0;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_LONG(length)
@ -154,17 +153,16 @@ PHP_METHOD(Random_Randomizer, getBytes)
}
retval = zend_string_alloc(length, 0);
required_size = length;
while (total_size < required_size) {
result = randomizer->algo->generate(randomizer->status);
while (total_size < length) {
uint64_t result = randomizer->algo->generate(randomizer->status);
if (EG(exception)) {
zend_string_free(retval);
RETURN_THROWS();
}
for (size_t i = 0; i < randomizer->status->last_generated_size; i++) {
ZSTR_VAL(retval)[total_size++] = (result >> (i * 8)) & 0xff;
if (total_size >= required_size) {
if (total_size >= length) {
break;
}
}