]> granicus.if.org Git - php/commitdiff
Fixed bug #67169: []= after_array_splice incorrect
authorNikita Popov <nikic@php.net>
Fri, 2 May 2014 10:48:43 +0000 (12:48 +0200)
committerNikita Popov <nikic@php.net>
Fri, 2 May 2014 10:49:51 +0000 (12:49 +0200)
This fixes a regression I introduced in beta 1.

NEWS
Zend/tests/bug67169.phpt [new file with mode: 0644]
Zend/zend_hash.c

diff --git a/NEWS b/NEWS
index 72e91e810f962ca4aa84223ded2277bc12a4ab88..d0ce2f194049a18c08b96da8cd39a684d52f6907 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2014, PHP 5.6.0 Beta 3
 
+- Core:
+  . Fixed bug #67169 (array_splice all elements, then []= gives wrong index).
+    (Nikita)
+
 01 May 2014, PHP 5.6.0 Beta 2
 
 - CLI server:
diff --git a/Zend/tests/bug67169.phpt b/Zend/tests/bug67169.phpt
new file mode 100644 (file)
index 0000000..8aa6aaf
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+Bug #67169: array_splice all elements, then []= gives wrong index
+--FILE--
+<?php
+
+$array = array('a', 'b');
+array_splice($array, 0, 2);
+$array[] = 'c';
+var_dump($array);
+
+$array = array('a', 'b');
+array_shift($array);
+array_shift($array);
+$array[] = 'c';
+var_dump($array);
+
+?>
+--EXPECT--
+array(1) {
+  [0]=>
+  string(1) "c"
+}
+array(1) {
+  [0]=>
+  string(1) "c"
+}
index 309631338a49787ba0d148eca3698a489884283f..a9fd3e9a43d944019ece7d83bca54bb785337974 100644 (file)
@@ -487,6 +487,7 @@ ZEND_API void zend_hash_reindex(HashTable *ht, zend_bool only_integer_keys) {
 
        IS_CONSISTENT(ht);
        if (UNEXPECTED(ht->nNumOfElements == 0)) {
+               ht->nNextFreeElement = 0;
                return;
        }