Skip to content

Commit 853daab

Browse files
committed
ext/random: Reduce scope of variables
1 parent 3977650 commit 853daab

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

ext/random/engine_mt19937.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ static inline void mt19937_reload(php_random_status_state_mt19937 *state)
127127

128128
PHPAPI inline void php_random_mt19937_seed32(php_random_status_state_mt19937 *state, uint32_t seed)
129129
{
130-
uint32_t i, prev_state;
130+
uint32_t i;
131131

132132
/* Initialize generator state with seed
133133
See Knuth TAOCP Vol 2, 3rd Ed, p.106 for multiplier.
134134
In previous versions, most significant bits (MSBs) of the seed affect
135135
only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto. */
136136
state->state[0] = seed;
137137
for (i = 1; i < N; i++) {
138-
prev_state = state->state[i - 1];
138+
uint32_t prev_state = state->state[i - 1];
139139
state->state[i] = (1812433253U * (prev_state ^ (prev_state >> 30)) + i) & 0xffffffffU;
140140
}
141141
state->count = i;

ext/random/engine_pcgoneseq128xslrr64.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,14 @@ static bool unserialize(void *state, HashTable *data)
8484
{
8585
php_random_status_state_pcgoneseq128xslrr64 *s = state;
8686
uint64_t u[2];
87-
zval *t;
8887

8988
/* Verify the expected number of elements, this implicitly ensures that no additional elements are present. */
9089
if (zend_hash_num_elements(data) != 2) {
9190
return false;
9291
}
9392

9493
for (uint32_t i = 0; i < 2; i++) {
95-
t = zend_hash_index_find(data, i);
94+
zval *t = zend_hash_index_find(data, i);
9695
if (!t || Z_TYPE_P(t) != IS_STRING || Z_STRLEN_P(t) != (2 * sizeof(uint64_t))) {
9796
return false;
9897
}

ext/random/engine_xoshiro256starstar.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,14 @@ static bool serialize(void *state, HashTable *data)
134134
static bool unserialize(void *state, HashTable *data)
135135
{
136136
php_random_status_state_xoshiro256starstar *s = state;
137-
zval *t;
138137

139138
/* Verify the expected number of elements, this implicitly ensures that no additional elements are present. */
140139
if (zend_hash_num_elements(data) != 4) {
141140
return false;
142141
}
143142

144143
for (uint32_t i = 0; i < 4; i++) {
145-
t = zend_hash_index_find(data, i);
144+
zval *t = zend_hash_index_find(data, i);
146145
if (!t || Z_TYPE_P(t) != IS_STRING || Z_STRLEN_P(t) != (2 * sizeof(uint64_t))) {
147146
return false;
148147
}

ext/random/randomizer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ PHP_METHOD(Random_Randomizer, shuffleBytes)
381381
PHP_METHOD(Random_Randomizer, pickArrayKeys)
382382
{
383383
php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
384-
zval *input, t;
384+
zval *input;
385385
zend_long num_req;
386386

387387
ZEND_PARSE_PARAMETERS_START(2, 2);
@@ -401,6 +401,7 @@ PHP_METHOD(Random_Randomizer, pickArrayKeys)
401401

402402
/* Keep compatibility, But the result is always an array */
403403
if (Z_TYPE_P(return_value) != IS_ARRAY) {
404+
zval t;
404405
ZVAL_COPY_VALUE(&t, return_value);
405406
array_init(return_value);
406407
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &t);

0 commit comments

Comments
 (0)