com php-src: Make empty list() check stricter: Zend/tests/list _empty_error.phpt Zend/zend_compile.c
| From: | Nikita Popov | Date: | Fri, 09 Jan 2015 17:27:06 +0000 |
| Subject: | com php-src: Make empty list() check stricter: Zend/tests/list _empty_error.phpt Zend/zend_compile.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-84049@lists.php.net to get a copy of this message | ||
Commit: e9068cefb4d97483823f8ee4dc384da7adf0c124
Author: Nikita Popov <nikic@php.net> Fri, 9 Jan 2015 18:27:06 +0100
Parents: 41a249fef602b8cbfdc70fc8179e48cc1387b821
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e9068cefb4d97483823f8ee4dc384da7adf0c124
Log:
Make empty list() check stricter
Now also includes list()s with just commas in it.
Changed paths:
A Zend/tests/list_empty_error.phpt
M Zend/zend_compile.c
Diff:
diff --git a/Zend/tests/list_empty_error.phpt b/Zend/tests/list_empty_error.phpt
new file mode 100644
index 0000000..78de2e9
--- /dev/null
+++ b/Zend/tests/list_empty_error.phpt
@@ -0,0 +1,10 @@
+--TEST--
+Empty list() assignments are not allowed
+--FILE--
+<?php
+
+list(,,,,,,,,,,) = [];
+
+?>
+--EXPECTF--
+Fatal error: Cannot use empty list in %s on line %d
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 16b5cfa..654c539 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -2191,10 +2191,7 @@ static void zend_compile_list_assign(znode *result, zend_ast *ast, znode
*expr_n
{
zend_ast_list *list = zend_ast_get_list(ast);
uint32_t i;
-
- if (list->children == 1 && !list->child[0]) {
- zend_error_noreturn(E_COMPILE_ERROR, "Cannot use empty list");
- }
+ zend_bool has_elems = 0;
for (i = 0; i < list->children; ++i) {
zend_ast *var_ast = list->child[i];
@@ -2203,6 +2200,7 @@ static void zend_compile_list_assign(znode *result, zend_ast *ast, znode
*expr_n
if (var_ast == NULL) {
continue;
}
+ has_elems = 1;
dim_node.op_type = IS_CONST;
ZVAL_LONG(&dim_node.u.constant, i);
@@ -2214,6 +2212,11 @@ static void zend_compile_list_assign(znode *result, zend_ast *ast, znode
*expr_n
zend_emit_op(&fetch_result, ZEND_FETCH_LIST, expr_node, &dim_node);
zend_emit_assign_znode(var_ast, &fetch_result);
}
+
+ if (!has_elems) {
+ zend_error_noreturn(E_COMPILE_ERROR, "Cannot use empty list");
+ }
+
*result = *expr_node;
}
/* }}} */