From: Dmitry Stogov Date: Thu, 22 Mar 2018 13:37:34 +0000 (+0300) Subject: Fixed a behavior break introduced by d7f2dc4ec651628e10213625db6aee3559e214a9 X-Git-Tag: php-7.3.0alpha1~153 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8598240c69801479cef134bac29b12c233aca075;p=php Fixed a behavior break introduced by d7f2dc4ec651628e10213625db6aee3559e214a9 --- diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index d5de72e95a..0824efa27b 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -1060,11 +1060,6 @@ static zend_always_inline void _zend_hash_del_el_ex(HashTable *ht, uint32_t idx, } } idx = HT_HASH_TO_IDX(idx); - if (ht->nNumUsed - 1 == idx) { - do { - ht->nNumUsed--; - } while (ht->nNumUsed > 0 && (UNEXPECTED(Z_TYPE(ht->arData[ht->nNumUsed-1].val) == IS_UNDEF))); - } ht->nNumOfElements--; if (ht->nInternalPointer == idx || UNEXPECTED(HT_HAS_ITERATORS(ht))) { uint32_t new_idx; @@ -1083,6 +1078,12 @@ static zend_always_inline void _zend_hash_del_el_ex(HashTable *ht, uint32_t idx, } zend_hash_iterators_update(ht, idx, new_idx); } + if (ht->nNumUsed - 1 == idx) { + do { + ht->nNumUsed--; + } while (ht->nNumUsed > 0 && (UNEXPECTED(Z_TYPE(ht->arData[ht->nNumUsed-1].val) == IS_UNDEF))); + ht->nInternalPointer = MIN(ht->nInternalPointer, ht->nNumUsed); + } if (p->key) { zend_string_release(p->key); } diff --git a/ext/standard/tests/array/current_variation6.phpt b/ext/standard/tests/array/current_variation6.phpt new file mode 100644 index 0000000000..970c7d4045 --- /dev/null +++ b/ext/standard/tests/array/current_variation6.phpt @@ -0,0 +1,20 @@ +--TEST-- +Test current() function : internal pointer maintenance at the end of array +--FILE-- + 1, "bar" => 2, "baz" => 3]; +reset($array); +while ($cur = current($array)) { + var_dump($cur); + next($array); +} + +unset($array["baz"]); +$array[] = 4; +var_dump(current($array)); +?> +--EXPECT-- +int(1) +int(2) +int(3) +int(4)