Skip to content

Commit be1487c

Browse files
committed
Select rand_rangeXX() variant only based on the requested range
This fixes an incompatibility when wrapping native 32-bit engines with a userland engine. The latter always used the 64-bit range function which then used two 32-bit numbers from the underlying engine to fill the 64-bit range, whereas the native implementation used only one. Now the selection of the range variant only depends on the requested range. A 32-bit range uses the 32-bit variant (even for 64-bit engines), whereas a larger range uses the 64-bit variant. This was found in php#9410 (comment)
1 parent 0f696e2 commit be1487c

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ PHP NEWS
1313
- Random:
1414
. Fixed bug GH-9415 (Randomizer::getInt(0, 2**32 - 1) with Mt19937
1515
always returns 1). (timwolla)
16+
. Fixed Randomizer::getInt() consistency for 32-bit engines. (timwolla)
1617

1718
- Streams:
1819
. Fixed bug GH-9316 ($http_response_header is wrong for long status line).

ext/random/random.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ PHPAPI zend_long php_random_range(const php_random_algo *algo, php_random_status
313313
{
314314
zend_ulong umax = (zend_ulong) max - (zend_ulong) min;
315315

316-
if (algo->generate_size == 0 || algo->generate_size > sizeof(uint32_t) || umax > UINT32_MAX) {
316+
if (umax > UINT32_MAX) {
317317
return (zend_long) (rand_range64(algo, status, umax) + min);
318318
}
319319

0 commit comments

Comments
 (0)