com php-src: Fix the constant array case as well: Zend/tests/ar ray_literal_next_element_error.phpt Zend/zend_com pile.c Zend/zend_compile.h

From: Date: Wed, 28 Sep 2016 21:05:21 +0000
Subject: com php-src: Fix the constant array case as well: Zend/tests/ar ray_literal_next_element_error.phpt Zend/zend_com pile.c Zend/zend_compile.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-94756@lists.php.net to get a copy of this message
Commit: 40b8105cca1fa3cc4b696b059308b6d0f2827fa8 Author: Nikita Popov <nikic@php.net> Wed, 28 Sep 2016 23:05:21 +0200 Parents: 99bf19c177e272676c363565f5f7b7281a5f1acd Branches: PHP-5.6 PHP-7.0 PHP-7.1 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=40b8105cca1fa3cc4b696b059308b6d0f2827fa8 Log: Fix the constant array case as well Changed paths: M Zend/tests/array_literal_next_element_error.phpt M Zend/zend_compile.c M Zend/zend_compile.h Diff: diff --git a/Zend/tests/array_literal_next_element_error.phpt b/Zend/tests/array_literal_next_element_error.phpt index 59ffeb0..8b4af3c 100644 --- a/Zend/tests/array_literal_next_element_error.phpt +++ b/Zend/tests/array_literal_next_element_error.phpt @@ -7,6 +7,9 @@ $i = PHP_INT_MAX; $array = [$i => 42, new stdClass]; var_dump($array); +const FOO = [PHP_INT_MAX => 42, "foo"]; +var_dump(FOO); + ?> --EXPECTF-- Warning: Cannot add element to the array as the next element is already occupied in %s on line %d @@ -14,3 +17,9 @@ array(1) { [%d]=> int(42) } + +Warning: Cannot add element to the array as the next element is already occupied in %s on line %d +array(1) { + [%d]=> + int(42) +} diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 5b67ef8..d3bec37 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -5929,7 +5929,7 @@ void zend_do_add_array_element(znode *result, const znode *expr, const znode *of } /* }}} */ -void zend_do_add_static_array_element(zval *result, zval *offset, const zval *expr) /* {{{ */ +void zend_do_add_static_array_element(zval *result, zval *offset, zval *expr) /* {{{ */ { if (offset) { switch (Z_TYPE_P(offset)) { @@ -5952,7 +5952,10 @@ void zend_do_add_static_array_element(zval *result, zval *offset, const zval *ex break; } } else { - zend_hash_next_index_insert(Z_ARRVAL_P(result), &expr, sizeof(zval *), NULL); + if (zend_hash_next_index_insert(Z_ARRVAL_P(result), &expr, sizeof(zval *), NULL) == FAILURE) { + zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied"); + zval_ptr_dtor(&expr); + } } } /* }}} */ diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index e7a7325..a0955e3 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -598,7 +598,7 @@ void zend_do_shell_exec(znode *result, const znode *cmd TSRMLS_DC); void zend_do_init_array(znode *result, const znode *expr, const znode *offset, zend_bool is_ref TSRMLS_DC); void zend_do_add_array_element(znode *result, const znode *expr, const znode *offset, zend_bool is_ref TSRMLS_DC); -void zend_do_add_static_array_element(zval *result, zval *offset, const zval *expr); +void zend_do_add_static_array_element(zval *result, zval *offset, zval *expr); void zend_do_list_init(TSRMLS_D); void zend_do_list_end(znode *result, znode *expr TSRMLS_DC); void zend_do_add_list_element(const znode *element TSRMLS_DC);

« previous php.cvs (#94756) next »