Skip to content

Commit 2c659ed

Browse files
committed
Make maximum argument to random_int() optional with default to INT_MAX.
1 parent b32e0d0 commit 2c659ed

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ext/standard/random.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,15 @@ PHP_FUNCTION(random_int)
168168
zend_long size;
169169
size_t i;
170170

171-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &maximum) == FAILURE) {
171+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &maximum) == FAILURE) {
172172
return;
173173
}
174174

175-
if (maximum <= 0 || maximum >= INT_MAX) {
175+
if (ZEND_NUM_ARGS() == 0) {
176+
maximum = INT_MAX;
177+
}
178+
179+
if (maximum <= 0 || maximum > INT_MAX) {
176180
php_error_docref(NULL, E_WARNING, "Cannot use maximum less than 1 or greater than %d", INT_MAX);
177181
RETURN_FALSE;
178182
}

0 commit comments

Comments
 (0)