-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix GH-12826: Weird pointers issue in nested loops
This regressed in cd53ce8. The loop with `zend_hash_iterators_update` hangs forever because `iter_pos` can't advance to idx. This is because the `zend_hash_iterators_lower_pos` upper bound is `target->nNumUsed`, but that is set to `source->nNumOfElements`. That means that if there are holes in the array, we still loop over all the buckets but the number of bucket slots will not match. Fix it by changing the assignment. Closes GH-12831.
- Loading branch information
Showing
3 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--TEST-- | ||
GH-12826 (Weird pointers issue in nested loops) | ||
--FILE-- | ||
<?php | ||
$test = array( | ||
'a' => 1, | ||
'b' => 2, | ||
'c' => 3, | ||
'd' => 4, | ||
); | ||
|
||
unset($test['a']); | ||
unset($test['b']); | ||
|
||
foreach($test as $k => &$v) { // Mind the reference! | ||
echo "Pass $k : "; | ||
|
||
foreach($test as $kk => $vv) { | ||
echo $test[$kk]; | ||
if ($kk == $k) $test[$kk] = 0; | ||
} | ||
|
||
echo "\n"; | ||
} | ||
|
||
unset($v); | ||
?> | ||
--EXPECT-- | ||
Pass c : 34 | ||
Pass d : 04 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters