mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
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:
parent
28a4d7676a
commit
ca399841ad
1 changed files with 4 additions and 6 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue