Skip to content

Commit 2462f2d

Browse files
committed
Fix #79364: When copy empty array, next key is unspecified
We must not forget to keep the `nNextFreeElement` when duplicating empty arrays.
1 parent d5e2066 commit 2462f2d

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 7.3.17
44

5+
- Core:
6+
. Fixed bug #79364 (When copy empty array, next key is unspecified). (cmb)
7+
58
- Spl:
69
. Fixed bug #75673 (SplStack::unserialize() behavior). (cmb)
710

Zend/tests/bug79364.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #79364 (When copy empty array, next key is unspecified)
3+
--FILE--
4+
<?php
5+
$a = [1, 2];
6+
unset($a[1], $a[0]);
7+
$b = $a;
8+
9+
$a[] = 3;
10+
$b[] = 4;
11+
12+
var_dump($a, $b);
13+
?>
14+
--EXPECT--
15+
array(1) {
16+
[2]=>
17+
int(3)
18+
}
19+
array(1) {
20+
[2]=>
21+
int(4)
22+
}

Zend/zend_hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(HashTable *source)
19341934
target->nTableMask = HT_MIN_MASK;
19351935
target->nNumUsed = 0;
19361936
target->nNumOfElements = 0;
1937-
target->nNextFreeElement = 0;
1937+
target->nNextFreeElement = source->nNextFreeElement;
19381938
target->nInternalPointer = 0;
19391939
HT_SET_DATA_ADDR(target, &uninitialized_bucket);
19401940
} else if (GC_FLAGS(source) & IS_ARRAY_IMMUTABLE) {

0 commit comments

Comments
 (0)