Skip to content

Commit 0cf3dbf

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 0cf3dbf

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

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)