@@ -180,7 +180,7 @@ ZEND_API void ZEND_FASTCALL _zend_hash_init(HashTable *ht, uint32_t nSize, dtor_
180
180
ht -> nNumUsed = 0 ;
181
181
ht -> nNumOfElements = 0 ;
182
182
ht -> nInternalPointer = HT_INVALID_IDX ;
183
- ht -> nNextFreeElement = 0 ;
183
+ ht -> nNextFreeElement = ZEND_LONG_MIN ;
184
184
ht -> pDestructor = pDestructor ;
185
185
ht -> nTableSize = zend_hash_check_size (nSize );
186
186
}
@@ -712,6 +712,10 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht,
712
712
IS_CONSISTENT (ht );
713
713
HT_ASSERT_RC1 (ht );
714
714
715
+ if (h == ZEND_LONG_MIN && flag & HASH_ADD_NEXT ) {
716
+ h = 0 ;
717
+ }
718
+
715
719
if (UNEXPECTED (!(ht -> u .flags & HASH_FLAG_INITIALIZED ))) {
716
720
CHECK_INIT (ht , h < ht -> nTableSize );
717
721
if (h < ht -> nTableSize ) {
@@ -795,8 +799,8 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht,
795
799
ZEND_HASH_IF_FULL_DO_RESIZE (ht ); /* If the Hash table is full, resize it */
796
800
797
801
add_to_hash :
798
- /* If the first index is negative, dont force the next index to be 0 */
799
- if (UNEXPECTED (( zend_long ) h < 0 && ht -> nNumOfElements == 0 ) ) {
802
+ /* Initialize nNextFreeElement with the value of the first numeric index */
803
+ if (ht -> nNextFreeElement == ZEND_LONG_MIN ) {
800
804
ht -> nNextFreeElement = h ;
801
805
}
802
806
idx = ht -> nNumUsed ++ ;
@@ -1400,7 +1404,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_clean(HashTable *ht)
1400
1404
}
1401
1405
ht -> nNumUsed = 0 ;
1402
1406
ht -> nNumOfElements = 0 ;
1403
- ht -> nNextFreeElement = 0 ;
1407
+ ht -> nNextFreeElement = ZEND_LONG_MIN ;
1404
1408
ht -> nInternalPointer = HT_INVALID_IDX ;
1405
1409
}
1406
1410
@@ -1439,7 +1443,7 @@ ZEND_API void ZEND_FASTCALL zend_symtable_clean(HashTable *ht)
1439
1443
}
1440
1444
ht -> nNumUsed = 0 ;
1441
1445
ht -> nNumOfElements = 0 ;
1442
- ht -> nNextFreeElement = 0 ;
1446
+ ht -> nNextFreeElement = ZEND_LONG_MIN ;
1443
1447
ht -> nInternalPointer = HT_INVALID_IDX ;
1444
1448
}
1445
1449
@@ -1776,7 +1780,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(HashTable *source)
1776
1780
target -> nTableMask = HT_MIN_MASK ;
1777
1781
target -> nNumUsed = 0 ;
1778
1782
target -> nNumOfElements = 0 ;
1779
- target -> nNextFreeElement = 0 ;
1783
+ target -> nNextFreeElement = ZEND_LONG_MIN ;
1780
1784
target -> nInternalPointer = HT_INVALID_IDX ;
1781
1785
HT_SET_DATA_ADDR (target , & uninitialized_bucket );
1782
1786
} else if (GC_FLAGS (source ) & IS_ARRAY_IMMUTABLE ) {
0 commit comments