@@ -278,7 +278,6 @@ PHP_METHOD(Random_Randomizer, getBytes)
278
278
279
279
zend_string * retval ;
280
280
zend_long user_length ;
281
- size_t total_size = 0 ;
282
281
283
282
ZEND_PARSE_PARAMETERS_START (1 , 1 )
284
283
Z_PARAM_LONG (user_length )
@@ -293,32 +292,34 @@ PHP_METHOD(Random_Randomizer, getBytes)
293
292
retval = zend_string_alloc (length , 0 );
294
293
char * rptr = ZSTR_VAL (retval );
295
294
296
- while (total_size < length ) {
295
+ size_t to_read = length ;
296
+ while (to_read > 0 ) {
297
297
php_random_result result = engine .algo -> generate (engine .state );
298
298
if (EG (exception )) {
299
299
zend_string_free (retval );
300
300
RETURN_THROWS ();
301
301
}
302
302
uint64_t tmp_ret = result .result ;
303
- if (length - total_size >= sizeof (uint64_t ) && result .size == sizeof (uint64_t )) {
303
+ if (to_read >= sizeof (uint64_t ) && result .size == sizeof (uint64_t )) {
304
304
#ifdef WORDS_BIGENDIAN
305
305
tmp_ret = RANDOM_BSWAP64 (tmp_ret );
306
306
#endif
307
307
memcpy (rptr , & tmp_ret , sizeof (uint64_t ));
308
- total_size + = sizeof (uint64_t );
308
+ to_read - = sizeof (uint64_t );
309
309
rptr += sizeof (uint64_t );
310
310
} else {
311
311
for (size_t i = 0 ; i < result .size ; i ++ ) {
312
- rptr [ total_size ++ ] = tmp_ret & 0xff ;
312
+ * rptr ++ = tmp_ret & 0xff ;
313
313
tmp_ret >>= 8 ;
314
- if (total_size >= length ) {
314
+ to_read -- ;
315
+ if (to_read == 0 ) {
315
316
break ;
316
317
}
317
318
}
318
319
}
319
320
}
320
321
321
- rptr [ length ] = '\0' ;
322
+ * rptr = '\0' ;
322
323
RETURN_STR (retval );
323
324
}
324
325
/* }}} */
0 commit comments