Skip to content

Commit da3add2

Browse files
committed
Fixed bug #67693 - incorrect push to the empty array
1 parent ab6c1d2 commit da3add2

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Diff for: ext/standard/array.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2020,7 +2020,7 @@ static void _phpi_pop(INTERNAL_FUNCTION_PARAMETERS, int off_the_end)
20202020
if (should_rehash) {
20212021
zend_hash_rehash(Z_ARRVAL_P(stack));
20222022
}
2023-
} else if (!key_len && index >= Z_ARRVAL_P(stack)->nNextFreeElement - 1) {
2023+
} else if (!key_len && Z_ARRVAL_P(stack)->nNextFreeElement > 0 && index >= Z_ARRVAL_P(stack)->nNextFreeElement - 1) {
20242024
Z_ARRVAL_P(stack)->nNextFreeElement = Z_ARRVAL_P(stack)->nNextFreeElement - 1;
20252025
}
20262026

Diff for: ext/standard/tests/array/bug67693.phpt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Bug #67693 - incorrect push to empty array
3+
--FILE--
4+
<?php
5+
6+
$array = array(-1 => 0);
7+
8+
array_pop($array);
9+
10+
array_push($array, 0);
11+
array_push($array, 0);
12+
13+
var_dump($array);
14+
15+
echo"\nDone";
16+
?>
17+
--EXPECT--
18+
array(2) {
19+
[0]=>
20+
int(0)
21+
[1]=>
22+
int(0)
23+
}
24+
25+
Done

0 commit comments

Comments
 (0)