diff --git a/NEWS b/NEWS index 67d13a61d5c2..df3ab007f7df 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,10 @@ PHP NEWS . Fixed bug GH-9285 (Traits cannot be used in readonly classes). (kocsismate) +- Random: + . Fixed bug GH-9415 (Randomizer::getInt(0, 2**32 - 1) with Mt19937 + always returns 1). (timwolla) + - Streams: . Fixed bug GH-9316 ($http_response_header is wrong for long status line). (cmb, timwolla) diff --git a/ext/random/random.c b/ext/random/random.c index ba25e5c04f04..b0cf8cb6f2c1 100644 --- a/ext/random/random.c +++ b/ext/random/random.c @@ -107,7 +107,7 @@ static inline uint32_t rand_range32(const php_random_algo *algo, php_random_stat /* Special case where no modulus is required */ if (UNEXPECTED(umax == UINT32_MAX)) { - return true; + return result; } /* Increment the max so range is inclusive of max */ diff --git a/ext/random/tests/03_randomizer/gh9415.phpt b/ext/random/tests/03_randomizer/gh9415.phpt new file mode 100644 index 000000000000..c624cb785739 --- /dev/null +++ b/ext/random/tests/03_randomizer/gh9415.phpt @@ -0,0 +1,19 @@ +--TEST-- +GH-9415: Randomizer::getInt(0, 2**32 - 1) with Mt19937 always returns 1 +--FILE-- +getInt(-2147483648, 2147483647)); + +$randomizer = new Randomizer(new Mt19937(4321)); +var_dump($randomizer->getInt(-2147483648, 2147483647)); + +?> +--EXPECT-- +int(-1324913873) +int(-1843387587)