@@ -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 ) {
@@ -764,7 +768,7 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht,
764
768
}
765
769
zend_hash_iterators_update (ht , HT_INVALID_IDX , h );
766
770
if ((zend_long )h >= (zend_long )ht -> nNextFreeElement ) {
767
- ht -> nNextFreeElement = h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX ;
771
+ ht -> nNextFreeElement = ( zend_long ) h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX ;
768
772
}
769
773
p -> h = h ;
770
774
p -> key = NULL ;
@@ -786,7 +790,7 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht,
786
790
}
787
791
ZVAL_COPY_VALUE (& p -> val , pData );
788
792
if ((zend_long )h >= (zend_long )ht -> nNextFreeElement ) {
789
- ht -> nNextFreeElement = h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX ;
793
+ ht -> nNextFreeElement = ( zend_long ) h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX ;
790
794
}
791
795
return & p -> val ;
792
796
}
@@ -795,14 +799,18 @@ 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 :
802
+ /* Initialize nNextFreeElement with the value of the first numeric index */
803
+ if (ht -> nNextFreeElement == ZEND_LONG_MIN ) {
804
+ ht -> nNextFreeElement = h ;
805
+ }
798
806
idx = ht -> nNumUsed ++ ;
799
807
ht -> nNumOfElements ++ ;
800
808
if (ht -> nInternalPointer == HT_INVALID_IDX ) {
801
809
ht -> nInternalPointer = idx ;
802
810
}
803
811
zend_hash_iterators_update (ht , HT_INVALID_IDX , idx );
804
812
if ((zend_long )h >= (zend_long )ht -> nNextFreeElement ) {
805
- ht -> nNextFreeElement = h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX ;
813
+ ht -> nNextFreeElement = ( zend_long ) h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX ;
806
814
}
807
815
p = ht -> arData + idx ;
808
816
p -> h = h ;
@@ -1396,7 +1404,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_clean(HashTable *ht)
1396
1404
}
1397
1405
ht -> nNumUsed = 0 ;
1398
1406
ht -> nNumOfElements = 0 ;
1399
- ht -> nNextFreeElement = 0 ;
1407
+ ht -> nNextFreeElement = ZEND_LONG_MIN ;
1400
1408
ht -> nInternalPointer = HT_INVALID_IDX ;
1401
1409
}
1402
1410
@@ -1435,7 +1443,7 @@ ZEND_API void ZEND_FASTCALL zend_symtable_clean(HashTable *ht)
1435
1443
}
1436
1444
ht -> nNumUsed = 0 ;
1437
1445
ht -> nNumOfElements = 0 ;
1438
- ht -> nNextFreeElement = 0 ;
1446
+ ht -> nNextFreeElement = ZEND_LONG_MIN ;
1439
1447
ht -> nInternalPointer = HT_INVALID_IDX ;
1440
1448
}
1441
1449
@@ -1772,7 +1780,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(HashTable *source)
1772
1780
target -> nTableMask = HT_MIN_MASK ;
1773
1781
target -> nNumUsed = 0 ;
1774
1782
target -> nNumOfElements = 0 ;
1775
- target -> nNextFreeElement = 0 ;
1783
+ target -> nNextFreeElement = ZEND_LONG_MIN ;
1776
1784
target -> nInternalPointer = HT_INVALID_IDX ;
1777
1785
HT_SET_DATA_ADDR (target , & uninitialized_bucket );
1778
1786
} else if (GC_FLAGS (source ) & IS_ARRAY_IMMUTABLE ) {
0 commit comments