@@ -81,9 +81,8 @@ PHPAPI uint32_t php_random_range32(php_random_algo_with_state engine, uint32_t u
81
81
const php_random_algo * algo = engine .algo ;
82
82
void * state = engine .state ;
83
83
84
- uint32_t result , limit ;
85
- size_t total_size = 0 ;
86
- uint32_t count = 0 ;
84
+ uint32_t result ;
85
+ size_t total_size ;
87
86
88
87
result = 0 ;
89
88
total_size = 0 ;
@@ -110,9 +109,10 @@ PHPAPI uint32_t php_random_range32(php_random_algo_with_state engine, uint32_t u
110
109
}
111
110
112
111
/* Ceiling under which UINT32_MAX % max == 0 */
113
- limit = UINT32_MAX - (UINT32_MAX % umax ) - 1 ;
112
+ uint32_t limit = UINT32_MAX - (UINT32_MAX % umax ) - 1 ;
114
113
115
114
/* Discard numbers over the limit to avoid modulo bias */
115
+ uint32_t count = 0 ;
116
116
while (UNEXPECTED (result > limit )) {
117
117
/* If the requirements cannot be met in a cycles, return fail */
118
118
if (++ count > PHP_RANDOM_RANGE_ATTEMPTS ) {
@@ -140,9 +140,8 @@ PHPAPI uint64_t php_random_range64(php_random_algo_with_state engine, uint64_t u
140
140
const php_random_algo * algo = engine .algo ;
141
141
void * state = engine .state ;
142
142
143
- uint64_t result , limit ;
144
- size_t total_size = 0 ;
145
- uint32_t count = 0 ;
143
+ uint64_t result ;
144
+ size_t total_size ;
146
145
147
146
result = 0 ;
148
147
total_size = 0 ;
@@ -169,9 +168,10 @@ PHPAPI uint64_t php_random_range64(php_random_algo_with_state engine, uint64_t u
169
168
}
170
169
171
170
/* Ceiling under which UINT64_MAX % max == 0 */
172
- limit = UINT64_MAX - (UINT64_MAX % umax ) - 1 ;
171
+ uint64_t limit = UINT64_MAX - (UINT64_MAX % umax ) - 1 ;
173
172
174
173
/* Discard numbers over the limit to avoid modulo bias */
174
+ uint32_t count = 0 ;
175
175
while (UNEXPECTED (result > limit )) {
176
176
/* If the requirements cannot be met in a cycles, return fail */
177
177
if (++ count > PHP_RANDOM_RANGE_ATTEMPTS ) {
@@ -520,7 +520,7 @@ PHP_FUNCTION(mt_getrandmax)
520
520
ZEND_PARSE_PARAMETERS_NONE ();
521
521
522
522
/*
523
- * Melo: it could be 2^^32 but we only use 2^^31 to maintain
523
+ * Melo: it could be 2^^32, but we only use 2^^31 to maintain
524
524
* compatibility with the previous php_rand
525
525
*/
526
526
RETURN_LONG (PHP_MT_RAND_MAX ); /* 2^^31 */
@@ -614,7 +614,7 @@ PHPAPI uint64_t php_random_generate_fallback_seed(void)
614
614
{
615
615
/* Mix various values using SHA-1 as a PRF to obtain as
616
616
* much entropy as possible, hopefully generating an
617
- * unpredictable and independent uint64_t. Nevertheless
617
+ * unpredictable and independent uint64_t. Nevertheless,
618
618
* the output of this function MUST NOT be treated as
619
619
* being cryptographically safe.
620
620
*/
0 commit comments