From: Matt Wilmas Date: Sun, 7 Jun 2009 19:28:02 +0000 (+0000) Subject: Fixed bug #47836 (array operator [] inconsistency when the array has PHP_INT_MAX... X-Git-Tag: php-5.4.0alpha1~191^2~3392 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=756d134c45dffea28ba861106408f6eec99193d2;p=php Fixed bug #47836 (array operator [] inconsistency when the array has PHP_INT_MAX index value) Also simplified related array_push() test --- diff --git a/Zend/tests/bug47836.phpt b/Zend/tests/bug47836.phpt new file mode 100644 index 0000000000..5a93a44c71 --- /dev/null +++ b/Zend/tests/bug47836.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #47836 (array operator [] inconsistency when the array has PHP_INT_MAX index value) +--FILE-- + +--EXPECTF-- +Warning: Cannot add element to the array as the next element is already occupied in %s on line 4 +array(1) { + [%d]=> + int(1) +} diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index 5e4429e4fe..cdb7eea896 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -507,7 +507,7 @@ ZEND_API int _zend_hash_index_update_or_next_insert(HashTable *ht, ulong h, void UPDATE_DATA(ht, p, pData, nDataSize); HANDLE_UNBLOCK_INTERRUPTIONS(); if ((long)h >= (long)ht->nNextFreeElement) { - ht->nNextFreeElement = h + 1; + ht->nNextFreeElement = h < LONG_MAX ? h + 1 : LONG_MAX; } if (pDest) { *pDest = p->pData; @@ -537,7 +537,7 @@ ZEND_API int _zend_hash_index_update_or_next_insert(HashTable *ht, ulong h, void HANDLE_UNBLOCK_INTERRUPTIONS(); if ((long)h >= (long)ht->nNextFreeElement) { - ht->nNextFreeElement = h + 1; + ht->nNextFreeElement = h < LONG_MAX ? h + 1 : LONG_MAX; } ht->nNumOfElements++; ZEND_HASH_IF_FULL_DO_RESIZE(ht); diff --git a/ext/standard/tests/array/array_push_error2.phpt b/ext/standard/tests/array/array_push_error2.phpt index 4e0aad0848..839b378f37 100644 --- a/ext/standard/tests/array/array_push_error2.phpt +++ b/ext/standard/tests/array/array_push_error2.phpt @@ -1,5 +1,5 @@ --TEST-- -Test array_push() function : error conditions - min and max int values as keys +Test array_push() function : error conditions - max int value as key --FILE-- 'min', PHP_INT_MAX => 'max'); +$array = array(PHP_INT_MAX => 'max'); var_dump(array_push($array, 'new')); var_dump($array); -var_dump(array_push($array, 'var')); -var_dump($array); echo "Done"; ?> --EXPECTF-- *** Testing array_push() : error conditions *** -int(3) -array(3) { - [-%d]=> - unicode(3) "min" - [%d]=> - unicode(3) "max" - [-%d]=> - unicode(3) "new" -} Warning: array_push(): Cannot add element to the array as the next element is already occupied in %s on line %d bool(false) -array(3) { - [-%d]=> - unicode(3) "min" +array(1) { [%d]=> unicode(3) "max" - [-%d]=> - unicode(3) "new" } Done