Skip to content

Commit 3ba7756

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Remove superfluous helper variable in `Randomizer::getBytes()` (#9563)
2 parents c398694 + ca39984 commit 3ba7756

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

ext/random/randomizer.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ PHP_METHOD(Random_Randomizer, getBytes)
141141
php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
142142
zend_string *retval;
143143
zend_long length;
144-
uint64_t result;
145-
size_t total_size = 0, required_size;
144+
size_t total_size = 0;
146145

147146
ZEND_PARSE_PARAMETERS_START(1, 1)
148147
Z_PARAM_LONG(length)
@@ -154,17 +153,16 @@ PHP_METHOD(Random_Randomizer, getBytes)
154153
}
155154

156155
retval = zend_string_alloc(length, 0);
157-
required_size = length;
158156

159-
while (total_size < required_size) {
160-
result = randomizer->algo->generate(randomizer->status);
157+
while (total_size < length) {
158+
uint64_t result = randomizer->algo->generate(randomizer->status);
161159
if (EG(exception)) {
162160
zend_string_free(retval);
163161
RETURN_THROWS();
164162
}
165163
for (size_t i = 0; i < randomizer->status->last_generated_size; i++) {
166164
ZSTR_VAL(retval)[total_size++] = (result >> (i * 8)) & 0xff;
167-
if (total_size >= required_size) {
165+
if (total_size >= length) {
168166
break;
169167
}
170168
}

0 commit comments

Comments
 (0)