com php-src: mt_rand 32/64-bit consistency: e xt/standard/mt_rand.c

From: Date: Sat, 06 Aug 2016 10:15:26 +0000
Subject: com php-src: mt_rand 32/64-bit consistency: e xt/standard/mt_rand.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-93643@lists.php.net to get a copy of this message
Commit: 5bf39267eec42a76334ce0afdfaa3b28a7f222cd Author: Leigh <leigh@php.net> Sat, 6 Aug 2016 11:15:26 +0100 Parents: be31515cc68a84892d05c4028b45190e54c33d83 Branches: PHP-7.1 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=5bf39267eec42a76334ce0afdfaa3b28a7f222cd Log: mt_rand 32/64-bit consistency Changed paths: M ext/standard/mt_rand.c Diff: diff --git a/ext/standard/mt_rand.c b/ext/standard/mt_rand.c index 2be8d5d..39b4200 100644 --- a/ext/standard/mt_rand.c +++ b/ext/standard/mt_rand.c @@ -218,9 +218,11 @@ PHPAPI zend_long php_mt_rand_range(zend_long min, zend_long max) zend_ulong result; result = php_mt_rand(); +#if ZEND_ULONG_MAX > UINT32_MAX if (umax > UINT32_MAX) { result = (result << 32) | php_mt_rand(); } +#endif /* Special case where no modulus is required */ if (UNEXPECTED(umax == ZEND_ULONG_MAX)) { @@ -238,7 +240,12 @@ PHPAPI zend_long php_mt_rand_range(zend_long min, zend_long max) /* Discard numbers over the limit to avoid modulo bias */ while (UNEXPECTED(result > limit)) { #if ZEND_ULONG_MAX > UINT32_MAX - result = (result << 32) | php_mt_rand(); + if (umax > UINT32_MAX) { + result = (result << 32) | php_mt_rand(); + } + else { + result = php_mt_rand(); + } #else result = php_mt_rand(); #endif

« previous php.cvs (#93643) next »