@@ -764,7 +764,7 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht,
764
764
}
765
765
zend_hash_iterators_update (ht , HT_INVALID_IDX , h );
766
766
if ((zend_long )h >= (zend_long )ht -> nNextFreeElement ) {
767
- ht -> nNextFreeElement = h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX ;
767
+ ht -> nNextFreeElement = ( zend_long ) h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX ;
768
768
}
769
769
p -> h = h ;
770
770
p -> key = NULL ;
@@ -786,7 +786,7 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht,
786
786
}
787
787
ZVAL_COPY_VALUE (& p -> val , pData );
788
788
if ((zend_long )h >= (zend_long )ht -> nNextFreeElement ) {
789
- ht -> nNextFreeElement = h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX ;
789
+ ht -> nNextFreeElement = ( zend_long ) h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX ;
790
790
}
791
791
return & p -> val ;
792
792
}
@@ -795,14 +795,18 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht,
795
795
ZEND_HASH_IF_FULL_DO_RESIZE (ht ); /* If the Hash table is full, resize it */
796
796
797
797
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 )) {
800
+ ht -> nNextFreeElement = h ;
801
+ }
798
802
idx = ht -> nNumUsed ++ ;
799
803
ht -> nNumOfElements ++ ;
800
804
if (ht -> nInternalPointer == HT_INVALID_IDX ) {
801
805
ht -> nInternalPointer = idx ;
802
806
}
803
807
zend_hash_iterators_update (ht , HT_INVALID_IDX , idx );
804
808
if ((zend_long )h >= (zend_long )ht -> nNextFreeElement ) {
805
- ht -> nNextFreeElement = h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX ;
809
+ ht -> nNextFreeElement = ( zend_long ) h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX ;
806
810
}
807
811
p = ht -> arData + idx ;
808
812
p -> h = h ;
0 commit comments