Skip to content

Commit 6a9127c

Browse files
committed
Assert that HT entries using add_new APIs are really new
1 parent ef05eab commit 6a9127c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Zend/zend_hash.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,12 +725,13 @@ static zend_always_inline zval *_zend_hash_add_or_update_i(HashTable *ht, zend_s
725725
zend_string_hash_val(key);
726726
}
727727
}
728-
} else if ((flag & HASH_ADD_NEW) == 0) {
728+
} else if ((flag & HASH_ADD_NEW) == 0 || ZEND_DEBUG) {
729729
p = zend_hash_find_bucket(ht, key, 0);
730730

731731
if (p) {
732732
zval *data;
733733

734+
ZEND_ASSERT((flag & HASH_ADD_NEW) == 0);
734735
if (flag & HASH_ADD) {
735736
if (!(flag & HASH_UPDATE_INDIRECT)) {
736737
return NULL;
@@ -1012,9 +1013,10 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht,
10121013
}
10131014
zend_hash_real_init_mixed(ht);
10141015
} else {
1015-
if ((flag & HASH_ADD_NEW) == 0) {
1016+
if ((flag & HASH_ADD_NEW) == 0 || ZEND_DEBUG) {
10161017
p = zend_hash_index_find_bucket(ht, h);
10171018
if (p) {
1019+
ZEND_ASSERT((flag & HASH_ADD_NEW) == 0);
10181020
goto replace;
10191021
}
10201022
}

0 commit comments

Comments
 (0)