summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-03-10 16:12:53 +0100
committerChristoph M. Becker <cmbecker69@gmx.de>2020-03-11 08:54:05 +0100
commit2462f2dab185f53544f2c5335ba6c16a007f3c71 (patch)
treef673e56348d85a42b640825e5e877be5fc0127f1
parentd5e206620b80b0f198f6dd1865a758edf7ea1494 (diff)
downloadphp-git-2462f2dab185f53544f2c5335ba6c16a007f3c71.tar.gz
Fix #79364: When copy empty array, next key is unspecified
We must not forget to keep the `nNextFreeElement` when duplicating empty arrays.
-rw-r--r--NEWS3
-rw-r--r--Zend/tests/bug79364.phpt22
-rw-r--r--Zend/zend_hash.c2
3 files changed, 26 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index f3750061e1..b290b23f81 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 7.3.17
+- Core:
+ . Fixed bug #79364 (When copy empty array, next key is unspecified). (cmb)
+
- Spl:
. Fixed bug #75673 (SplStack::unserialize() behavior). (cmb)
diff --git a/Zend/tests/bug79364.phpt b/Zend/tests/bug79364.phpt
new file mode 100644
index 0000000000..6d96b4d793
--- /dev/null
+++ b/Zend/tests/bug79364.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Bug #79364 (When copy empty array, next key is unspecified)
+--FILE--
+<?php
+$a = [1, 2];
+unset($a[1], $a[0]);
+$b = $a;
+
+$a[] = 3;
+$b[] = 4;
+
+var_dump($a, $b);
+?>
+--EXPECT--
+array(1) {
+ [2]=>
+ int(3)
+}
+array(1) {
+ [2]=>
+ int(4)
+}
diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c
index 8c0bce5b41..6fc4666da9 100644
--- a/Zend/zend_hash.c
+++ b/Zend/zend_hash.c
@@ -1934,7 +1934,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(HashTable *source)
target->nTableMask = HT_MIN_MASK;
target->nNumUsed = 0;
target->nNumOfElements = 0;
- target->nNextFreeElement = 0;
+ target->nNextFreeElement = source->nNextFreeElement;
target->nInternalPointer = 0;
HT_SET_DATA_ADDR(target, &uninitialized_bucket);
} else if (GC_FLAGS(source) & IS_ARRAY_IMMUTABLE) {