]> granicus.if.org Git - php/commitdiff
mt_rand 32/64-bit consistency
authorLeigh <leigh@php.net>
Sat, 6 Aug 2016 10:15:26 +0000 (11:15 +0100)
committerLeigh <leigh@php.net>
Sat, 6 Aug 2016 10:15:26 +0000 (11:15 +0100)
ext/standard/mt_rand.c

index 2be8d5d07571585dc539b8de83c0f155b4e4ebfc..39b4200bde65f6a3e6f38e52b5fdeb3e68351b55 100644 (file)
@@ -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