File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -291,6 +291,7 @@ PHP_METHOD(Random_Randomizer, getBytes)
291
291
292
292
size_t length = (size_t )user_length ;
293
293
retval = zend_string_alloc (length , 0 );
294
+ char * rptr = ZSTR_VAL (retval );
294
295
295
296
while (total_size < length ) {
296
297
php_random_result result = engine .algo -> generate (engine .state );
@@ -299,16 +300,25 @@ PHP_METHOD(Random_Randomizer, getBytes)
299
300
RETURN_THROWS ();
300
301
}
301
302
uint64_t tmp_ret = result .result ;
302
- for (size_t i = 0 ; i < result .size ; i ++ ) {
303
- ZSTR_VAL (retval )[total_size ++ ] = tmp_ret & 0xff ;
304
- tmp_ret >>= 8 ;
305
- if (total_size >= length ) {
306
- break ;
303
+ if (length - total_size >= sizeof (uint64_t ) && result .size == sizeof (uint64_t )) {
304
+ #ifdef WORDS_BIGENDIAN
305
+ tmp_ret = RANDOM_BSWAP64 (tmp_ret );
306
+ #endif
307
+ memcpy (rptr , & tmp_ret , sizeof (uint64_t ));
308
+ total_size += sizeof (uint64_t );
309
+ rptr += sizeof (uint64_t );
310
+ } else {
311
+ for (size_t i = 0 ; i < result .size ; i ++ ) {
312
+ rptr [total_size ++ ] = tmp_ret & 0xff ;
313
+ tmp_ret >>= 8 ;
314
+ if (total_size >= length ) {
315
+ break ;
316
+ }
307
317
}
308
318
}
309
319
}
310
320
311
- ZSTR_VAL ( retval ) [length ] = '\0' ;
321
+ rptr [length ] = '\0' ;
312
322
RETURN_STR (retval );
313
323
}
314
324
/* }}} */
You can’t perform that action at this time.
0 commit comments