cvs: ZendEngine2 / zend_hash.c /tests bug37715.phpt bug41372.phpt
| From: | Dmitry Stogov | Date: | Tue, 24 Jul 2007 18:28:53 +0000 |
| Subject: | cvs: ZendEngine2 / zend_hash.c /tests bug37715.phpt bug41372.phpt | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-5923@lists.php.net to get a copy of this message | ||
dmitry Tue Jul 24 18:28:53 2007 UTC
Modified files:
/ZendEngine2 zend_hash.c
/ZendEngine2/tests bug37715.phpt bug41372.phpt
Log:
Fixed bug #41372 (Internal pointer of source array resets during array copying)
Fixed bug #37715 (array pointers resetting on copy)
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_hash.c?r1=1.150&r2=1.151&diff_format=u
Index: ZendEngine2/zend_hash.c
diff -u ZendEngine2/zend_hash.c:1.150 ZendEngine2/zend_hash.c:1.151
--- ZendEngine2/zend_hash.c:1.150 Wed Jul 11 11:19:58 2007
+++ ZendEngine2/zend_hash.c Tue Jul 24 18:28:53 2007
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_hash.c,v 1.150 2007/07/11 11:19:58 tony2001 Exp $ */
+/* $Id: zend_hash.c,v 1.151 2007/07/24 18:28:53 dmitry Exp $ */
#include "zend.h"
#include "zend_operators.h"
@@ -1025,12 +1025,17 @@
{
Bucket *p;
void *new_entry;
+ zend_bool setTargetPointer;
IS_CONSISTENT(source);
IS_CONSISTENT(target);
+ setTargetPointer = !target->pInternalPointer;
p = source->pListHead;
while (p) {
+ if (setTargetPointer && source->pInternalPointer == p) {
+ target->pInternalPointer = NULL;
+ }
if (p->nKeyLength == 0) {
zend_hash_index_update(target, p->h, p->pData, size, &new_entry);
} else {
@@ -1041,7 +1046,9 @@
}
p = p->pListNext;
}
- target->pInternalPointer = target->pListHead;
+ if (!target->pInternalPointer) {
+ target->pInternalPointer = target->pListHead;
+ }
}
/* }}} */
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug37715.phpt?r1=1.1&r2=1.2&diff_format=u
Index: ZendEngine2/tests/bug37715.phpt
diff -u /dev/null ZendEngine2/tests/bug37715.phpt:1.2
--- /dev/null Tue Jul 24 18:28:53 2007
+++ ZendEngine2/tests/bug37715.phpt Tue Jul 24 18:28:53 2007
@@ -0,0 +1,29 @@
+--TEST--
+Bug #37715 (array pointers resetting on copy)
+--FILE--
+<?php
+$a = array(
+ 'a' => array(
+ 'A', 'B', 'C', 'D',
+ ),
+ 'b' => array(
+ 'AA', 'BB', 'CC', 'DD',
+ ),
+);
+
+// Set the pointer of $a to 'b' and the pointer of 'b' to 'CC'
+reset($a);
+next($a);
+next($a['b']);
+next($a['b']);
+next($a['b']);
+
+var_dump(key($a['b']));
+foreach($a as $k => $d)
+{
+}
+// Alternatively $c = $a; and foreachloop removal will cause identical results.
+var_dump(key($a['b']));
+--EXPECT--
+int(3)
+int(3)
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug41372.phpt?r1=1.1&r2=1.2&diff_format=u
Index: ZendEngine2/tests/bug41372.phpt
diff -u /dev/null ZendEngine2/tests/bug41372.phpt:1.2
--- /dev/null Tue Jul 24 18:28:53 2007
+++ ZendEngine2/tests/bug41372.phpt Tue Jul 24 18:28:53 2007
@@ -0,0 +1,13 @@
+--TEST--
+Bug #41372 Internal pointer of source array resets during array copying
+--FILE--
+<?php
+$Foo = array('val1', 'val2', 'val3');
+end($Foo);
+echo key($Foo),"\n";
+$MagicInternalPointerResetter = $Foo;
+echo key($Foo),"\n";
+?>
+--EXPECT--
+2
+2