@@ -181,7 +181,7 @@ static zend_always_inline void _zend_hash_init_int(HashTable *ht, uint32_t nSize
181
181
ht -> nNumUsed = 0 ;
182
182
ht -> nNumOfElements = 0 ;
183
183
ht -> nInternalPointer = HT_INVALID_IDX ;
184
- ht -> nNextFreeElement = 0 ;
184
+ ht -> nNextFreeElement = ZEND_LONG_MIN ;
185
185
ht -> pDestructor = pDestructor ;
186
186
ht -> nTableSize = zend_hash_check_size (nSize );
187
187
}
@@ -789,6 +789,10 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht,
789
789
IS_CONSISTENT (ht );
790
790
HT_ASSERT_RC1 (ht );
791
791
792
+ if (h == ZEND_LONG_MIN && flag & HASH_ADD_NEXT ) {
793
+ h = 0 ;
794
+ }
795
+
792
796
if (UNEXPECTED (!(HT_FLAGS (ht ) & HASH_FLAG_INITIALIZED ))) {
793
797
CHECK_INIT (ht , h < ht -> nTableSize );
794
798
if (h < ht -> nTableSize ) {
@@ -841,7 +845,7 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht,
841
845
}
842
846
zend_hash_iterators_update (ht , HT_INVALID_IDX , h );
843
847
if ((zend_long )h >= (zend_long )ht -> nNextFreeElement ) {
844
- ht -> nNextFreeElement = h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX ;
848
+ ht -> nNextFreeElement = ( zend_long ) h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX ;
845
849
}
846
850
p -> h = h ;
847
851
p -> key = NULL ;
@@ -863,7 +867,7 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht,
863
867
}
864
868
ZVAL_COPY_VALUE (& p -> val , pData );
865
869
if ((zend_long )h >= (zend_long )ht -> nNextFreeElement ) {
866
- ht -> nNextFreeElement = h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX ;
870
+ ht -> nNextFreeElement = ( zend_long ) h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX ;
867
871
}
868
872
return & p -> val ;
869
873
}
@@ -872,14 +876,18 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht,
872
876
ZEND_HASH_IF_FULL_DO_RESIZE (ht ); /* If the Hash table is full, resize it */
873
877
874
878
add_to_hash :
879
+ /* Initialize nNextFreeElement with the value of the first numeric index */
880
+ if (ht -> nNextFreeElement == ZEND_LONG_MIN ) {
881
+ ht -> nNextFreeElement = h ;
882
+ }
875
883
idx = ht -> nNumUsed ++ ;
876
884
ht -> nNumOfElements ++ ;
877
885
if (ht -> nInternalPointer == HT_INVALID_IDX ) {
878
886
ht -> nInternalPointer = idx ;
879
887
}
880
888
zend_hash_iterators_update (ht , HT_INVALID_IDX , idx );
881
889
if ((zend_long )h >= (zend_long )ht -> nNextFreeElement ) {
882
- ht -> nNextFreeElement = h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX ;
890
+ ht -> nNextFreeElement = ( zend_long ) h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX ;
883
891
}
884
892
p = ht -> arData + idx ;
885
893
p -> h = h ;
@@ -1471,7 +1479,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_clean(HashTable *ht)
1471
1479
}
1472
1480
ht -> nNumUsed = 0 ;
1473
1481
ht -> nNumOfElements = 0 ;
1474
- ht -> nNextFreeElement = 0 ;
1482
+ ht -> nNextFreeElement = ZEND_LONG_MIN ;
1475
1483
ht -> nInternalPointer = HT_INVALID_IDX ;
1476
1484
}
1477
1485
@@ -1510,7 +1518,7 @@ ZEND_API void ZEND_FASTCALL zend_symtable_clean(HashTable *ht)
1510
1518
}
1511
1519
ht -> nNumUsed = 0 ;
1512
1520
ht -> nNumOfElements = 0 ;
1513
- ht -> nNextFreeElement = 0 ;
1521
+ ht -> nNextFreeElement = ZEND_LONG_MIN ;
1514
1522
ht -> nInternalPointer = HT_INVALID_IDX ;
1515
1523
}
1516
1524
@@ -1837,7 +1845,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(HashTable *source)
1837
1845
target -> nTableMask = HT_MIN_MASK ;
1838
1846
target -> nNumUsed = 0 ;
1839
1847
target -> nNumOfElements = 0 ;
1840
- target -> nNextFreeElement = 0 ;
1848
+ target -> nNextFreeElement = ZEND_LONG_MIN ;
1841
1849
target -> nInternalPointer = HT_INVALID_IDX ;
1842
1850
HT_SET_DATA_ADDR (target , & uninitialized_bucket );
1843
1851
} else if (GC_FLAGS (source ) & IS_ARRAY_IMMUTABLE ) {
0 commit comments