Skip to content

Commit 9e3bd1b

Browse files
committed
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1: NEWS Fixed bug #75514 mt_rand returns value outside [$min,$max]+ on 32-bit
2 parents 2d88b2a + 3dbe8dd commit 9e3bd1b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Diff for: ext/standard/mt_rand.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,15 @@ PHPAPI zend_long php_mt_rand_range(zend_long min, zend_long max)
294294
* rand() allows min > max, mt_rand does not */
295295
PHPAPI zend_long php_mt_rand_common(zend_long min, zend_long max)
296296
{
297-
zend_long n;
297+
uint32_t n;
298298

299299
if (BG(mt_rand_mode) == MT_RAND_MT19937) {
300300
return php_mt_rand_range(min, max);
301301
}
302302

303303
/* Legacy mode deliberately not inside php_mt_rand_range()
304304
* to prevent other functions being affected */
305-
n = (zend_long)php_mt_rand() >> 1;
305+
n = php_mt_rand() >> 1;
306306
RAND_RANGE_BADSCALING(n, min, max, PHP_MT_RAND_MAX);
307307

308308
return n;

Diff for: ext/standard/tests/math/bug75514.phpt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #75514 mt_rand returns value outside [$min,$max]
3+
--FILE--
4+
<?php
5+
mt_srand(0, MT_RAND_PHP);
6+
var_dump(mt_rand(0,999999999), mt_rand(0,999));
7+
?>
8+
===Done===
9+
--EXPECT--
10+
int(448865905)
11+
int(592)
12+
===Done===

0 commit comments

Comments
 (0)