diff options
author | Dmitry Stogov <dmitry@zend.com> | 2014-07-29 18:19:41 +0400 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2014-07-29 18:19:41 +0400 |
commit | dda7e84f10bffb0eca57754e682530988edab235 (patch) | |
tree | 66151ba72a70f5baf0ae7bbc2832e146f1f24b8e | |
parent | 46fcd3fc08de938293a8a4fe25f9d1ed18457f4a (diff) | |
download | php-git-dda7e84f10bffb0eca57754e682530988edab235.tar.gz |
Fixed ext/standard/tests/array/unexpected_array_mod_bug.phpt
-rw-r--r-- | ext/standard/array.c | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c index 0e01b2ec68..731c374582 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -607,6 +607,7 @@ static int php_array_user_compare(const void *a, const void *b TSRMLS_DC) /* {{{ PHP_FUNCTION(usort) { zval *array; + zend_refcounted *arr; unsigned int refcount; PHP_ARRAY_CMP_FUNC_VARS; @@ -617,30 +618,31 @@ PHP_FUNCTION(usort) return; } - /* Clear the is_ref flag, so the attemts to modify the array in user + /* Increase reference counter, so the attemts to modify the array in user * comparison function will create a copy of array and won't affect the * original array. The fact of modification is detected using refcount * comparison. The result of sorting in such case is undefined and the * function returns FALSE. */ -//??? Z_UNSET_ISREF_P(array); + Z_ADDREF_P(array); refcount = Z_REFCOUNT_P(array); + arr = Z_COUNTED_P(array); if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_user_compare, 1 TSRMLS_CC) == FAILURE) { RETVAL_FALSE; } else { if (refcount > Z_REFCOUNT_P(array)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array was modified by the user comparison function"); + if (--GC_REFCOUNT(arr) <= 0) { + _zval_dtor_func(arr ZEND_FILE_LINE_CC); + } RETVAL_FALSE; } else { + Z_DELREF_P(array); RETVAL_TRUE; } } - if (Z_REFCOUNT_P(array) > 1) { -//??? Z_SET_ISREF_P(array); - } - PHP_ARRAY_CMP_FUNC_RESTORE(); } /* }}} */ @@ -650,6 +652,7 @@ PHP_FUNCTION(usort) PHP_FUNCTION(uasort) { zval *array; + zend_refcounted *arr; unsigned int refcount; PHP_ARRAY_CMP_FUNC_VARS; @@ -660,30 +663,31 @@ PHP_FUNCTION(uasort) return; } - /* Clear the is_ref flag, so the attemts to modify the array in user - * comaprison function will create a copy of array and won't affect the + /* Increase reference counter, so the attemts to modify the array in user + * comparison function will create a copy of array and won't affect the * original array. The fact of modification is detected using refcount * comparison. The result of sorting in such case is undefined and the * function returns FALSE. */ -//??? Z_UNSET_ISREF_P(array); + Z_ADDREF_P(array); refcount = Z_REFCOUNT_P(array); + arr = Z_COUNTED_P(array); if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_user_compare, 0 TSRMLS_CC) == FAILURE) { RETVAL_FALSE; } else { if (refcount > Z_REFCOUNT_P(array)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array was modified by the user comparison function"); + if (--GC_REFCOUNT(arr) <= 0) { + _zval_dtor_func(arr ZEND_FILE_LINE_CC); + } RETVAL_FALSE; } else { + Z_DELREF_P(array); RETVAL_TRUE; } } - if (Z_REFCOUNT_P(array) > 1) { -//??? Z_SET_ISREF_P(array); - } - PHP_ARRAY_CMP_FUNC_RESTORE(); } /* }}} */ @@ -736,6 +740,7 @@ static int php_array_user_key_compare(const void *a, const void *b TSRMLS_DC) /* PHP_FUNCTION(uksort) { zval *array; + zend_refcounted *arr; unsigned int refcount; PHP_ARRAY_CMP_FUNC_VARS; @@ -746,30 +751,31 @@ PHP_FUNCTION(uksort) return; } - /* Clear the is_ref flag, so the attemts to modify the array in user - * comaprison function will create a copy of array and won't affect the + /* Increase reference counter, so the attemts to modify the array in user + * comparison function will create a copy of array and won't affect the * original array. The fact of modification is detected using refcount * comparison. The result of sorting in such case is undefined and the * function returns FALSE. */ -//??? Z_UNSET_ISREF_P(array); + Z_ADDREF_P(array); refcount = Z_REFCOUNT_P(array); + arr = Z_COUNTED_P(array); if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_user_key_compare, 0 TSRMLS_CC) == FAILURE) { RETVAL_FALSE; } else { if (refcount > Z_REFCOUNT_P(array)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array was modified by the user comparison function"); + if (--GC_REFCOUNT(arr) <= 0) { + _zval_dtor_func(arr ZEND_FILE_LINE_CC); + } RETVAL_FALSE; } else { + Z_DELREF_P(array); RETVAL_TRUE; } } - if (Z_REFCOUNT_P(array) > 1) { -//??? Z_SET_ISREF_P(array); - } - PHP_ARRAY_CMP_FUNC_RESTORE(); } /* }}} */ |