Skip to content

Commit 2dc15a3

Browse files
committed
Consistency fixes for negative indexes
1 parent b83421e commit 2dc15a3

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

Zend/zend_hash.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ ZEND_API void ZEND_FASTCALL _zend_hash_init(HashTable *ht, uint32_t nSize, dtor_
180180
ht->nNumUsed = 0;
181181
ht->nNumOfElements = 0;
182182
ht->nInternalPointer = HT_INVALID_IDX;
183-
ht->nNextFreeElement = 0;
183+
ht->nNextFreeElement = ZEND_LONG_MIN;
184184
ht->pDestructor = pDestructor;
185185
ht->nTableSize = zend_hash_check_size(nSize);
186186
}
@@ -795,8 +795,8 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht,
795795
ZEND_HASH_IF_FULL_DO_RESIZE(ht); /* If the Hash table is full, resize it */
796796

797797
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)) {
798+
/* Initialize nNextFreeElement with the value of the first numeric index */
799+
if (ht->nNextFreeElement == ZEND_LONG_MIN) {
800800
ht->nNextFreeElement = h;
801801
}
802802
idx = ht->nNumUsed++;
@@ -1400,7 +1400,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_clean(HashTable *ht)
14001400
}
14011401
ht->nNumUsed = 0;
14021402
ht->nNumOfElements = 0;
1403-
ht->nNextFreeElement = 0;
1403+
ht->nNextFreeElement = ZEND_LONG_MIN;
14041404
ht->nInternalPointer = HT_INVALID_IDX;
14051405
}
14061406

@@ -1439,7 +1439,7 @@ ZEND_API void ZEND_FASTCALL zend_symtable_clean(HashTable *ht)
14391439
}
14401440
ht->nNumUsed = 0;
14411441
ht->nNumOfElements = 0;
1442-
ht->nNextFreeElement = 0;
1442+
ht->nNextFreeElement = ZEND_LONG_MIN;
14431443
ht->nInternalPointer = HT_INVALID_IDX;
14441444
}
14451445

@@ -1776,7 +1776,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(HashTable *source)
17761776
target->nTableMask = HT_MIN_MASK;
17771777
target->nNumUsed = 0;
17781778
target->nNumOfElements = 0;
1779-
target->nNextFreeElement = 0;
1779+
target->nNextFreeElement = ZEND_LONG_MIN;
17801780
target->nInternalPointer = HT_INVALID_IDX;
17811781
HT_SET_DATA_ADDR(target, &uninitialized_bucket);
17821782
} else if (GC_FLAGS(source) & IS_ARRAY_IMMUTABLE) {

Zend/zend_list.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ZEND_API zval *zend_list_insert(void *ptr, int type)
3737
zval zv;
3838

3939
index = zend_hash_next_free_element(&EG(regular_list));
40-
if (index == 0) {
40+
if (index == ZEND_LONG_MIN) {
4141
index = 1;
4242
}
4343
ZVAL_NEW_RES(&zv, index, ptr, type);

ext/standard/array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3266,7 +3266,7 @@ PHP_FUNCTION(array_pop)
32663266
ZVAL_DEREF(val);
32673267
ZVAL_COPY(return_value, val);
32683268

3269-
if (!p->key && Z_ARRVAL_P(stack)->nNextFreeElement > 0 && p->h >= (zend_ulong)(Z_ARRVAL_P(stack)->nNextFreeElement - 1)) {
3269+
if (!p->key && p->h >= (zend_ulong)(Z_ARRVAL_P(stack)->nNextFreeElement - 1)) {
32703270
Z_ARRVAL_P(stack)->nNextFreeElement = Z_ARRVAL_P(stack)->nNextFreeElement - 1;
32713271
}
32723272

0 commit comments

Comments
 (0)