Skip to content

Commit 1a16008

Browse files
committed
Improve range exceed array size error message
The start and end value are not necessarily the issue, it only is when the step parameter does to small increments
1 parent b02da6c commit 1a16008

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

ext/standard/array.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,7 +2647,7 @@ PHP_FUNCTION(array_fill_keys)
26472647
double __calc_size = ((start - end) / (_step)) + 1; \
26482648
if (__calc_size >= (double)HT_MAX_SIZE) { \
26492649
zend_value_error(\
2650-
"The supplied range exceeds the maximum array size: start=%0.0f end=%0.0f", end, start); \
2650+
"The supplied range exceeds the maximum array size: start=%0.1f end=%0.1f step=%0.1f", end, start, (_step)); \
26512651
RETURN_THROWS(); \
26522652
} \
26532653
size = (uint32_t)_php_math_round(__calc_size, 0, PHP_ROUND_HALF_UP); \
@@ -2659,7 +2659,7 @@ PHP_FUNCTION(array_fill_keys)
26592659
zend_ulong __calc_size = ((zend_ulong) start - end) / (_step); \
26602660
if (__calc_size >= HT_MAX_SIZE - 1) { \
26612661
zend_value_error(\
2662-
"The supplied range exceeds the maximum array size: start=" ZEND_LONG_FMT " end=" ZEND_LONG_FMT, end, start); \
2662+
"The supplied range exceeds the maximum array size: start=" ZEND_LONG_FMT " end=" ZEND_LONG_FMT " step=" ZEND_LONG_FMT, end, start, (_step)); \
26632663
RETURN_THROWS(); \
26642664
} \
26652665
size = (uint32_t)(__calc_size + 1); \

ext/standard/tests/array/range/range_bug70239_2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ try {
99
}
1010
?>
1111
--EXPECTF--
12-
The supplied range exceeds the maximum array size: start=0 end=%d
12+
The supplied range exceeds the maximum array size: start=0 end=%d step=1

ext/standard/tests/array/range/range_bug70239_3.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ try {
99
}
1010
?>
1111
--EXPECTF--
12-
The supplied range exceeds the maximum array size: start=-%d end=0
12+
The supplied range exceeds the maximum array size: start=-%d end=0 step=1
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Creating a range that exceeds the maximum array size
3+
--FILE--
4+
<?php
5+
try {
6+
var_dump(range(0, 100_000_000_000, 0.1));
7+
} catch (\ValueError $e) {
8+
echo $e->getMessage(), \PHP_EOL;
9+
}
10+
try {
11+
var_dump(range(PHP_INT_MIN, PHP_INT_MAX, 1));
12+
} catch (\ValueError $e) {
13+
echo $e->getMessage(), \PHP_EOL;
14+
}
15+
?>
16+
--EXPECTF--
17+
The supplied range exceeds the maximum array size: start=0.0 end=100000000000.0 step=0.1
18+
The supplied range exceeds the maximum array size: start=-%d end=%d step=1

0 commit comments

Comments
 (0)