mirror of
https://github.com/php/php-src.git
synced 2025-01-20 10:43:40 +08:00
Fixed bug #41372 (Internal pointer of source array resets during array copying)
Fixed bug #37715 (array pointers resetting on copy)
This commit is contained in:
parent
02b2d0a4ac
commit
215edd7a4a
29
Zend/tests/bug37715.phpt
Executable file
29
Zend/tests/bug37715.phpt
Executable file
@ -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)
|
13
Zend/tests/bug41372.phpt
Executable file
13
Zend/tests/bug41372.phpt
Executable file
@ -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
|
@ -1025,12 +1025,17 @@ ZEND_API void zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_fun
|
||||
{
|
||||
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 @@ ZEND_API void zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_fun
|
||||
}
|
||||
p = p->pListNext;
|
||||
}
|
||||
target->pInternalPointer = target->pListHead;
|
||||
if (!target->pInternalPointer) {
|
||||
target->pInternalPointer = target->pListHead;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user