]> granicus.if.org Git - php/commitdiff
Fix leak when yielding array as key
authorNikita Popov <nikic@php.net>
Sat, 1 Sep 2012 18:31:40 +0000 (20:31 +0200)
committerNikita Popov <nikic@php.net>
Sat, 1 Sep 2012 18:31:40 +0000 (20:31 +0200)
The code was copy-pasted and I forgot to change OP1 to OP2 in that one
place.

Zend/tests/generators/yield_array_key.phpt [new file with mode: 0644]
Zend/zend_vm_def.h
Zend/zend_vm_execute.h

diff --git a/Zend/tests/generators/yield_array_key.phpt b/Zend/tests/generators/yield_array_key.phpt
new file mode 100644 (file)
index 0000000..5afba00
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Array keys can be yielded from generators
+--FILE--
+<?php
+
+function gen() {
+    yield [] => 1;
+}
+
+$gen = gen();
+var_dump($gen->key());
+var_dump($gen->current());
+
+?>
+--EXPECT--
+array(0) {
+}
+int(1)
index ffd81b03785024053ae8881218e59231d428e84e..f683ff29727a6309027fd8ec1c3092589de30d4b 100644 (file)
@@ -5511,7 +5511,7 @@ ZEND_VM_HANDLER(160, ZEND_YIELD, CONST|TMP|VAR|CV|UNUSED, CONST|TMP|VAR|CV|UNUSE
                        INIT_PZVAL_COPY(copy, key);
 
                        /* Temporary variables don't need ctor copying */
-                       if (!IS_OP1_TMP_FREE()) {
+                       if (!IS_OP2_TMP_FREE()) {
                                zval_copy_ctor(copy);
                        }
 
index b0e05b1296aa98cf94a1520f5cdb4e2d5459d94b..f8a8905040008e58b92aa7f4b6823d0653e7ca19 100644 (file)
@@ -5005,7 +5005,7 @@ static int ZEND_FASTCALL  ZEND_YIELD_SPEC_CONST_TMP_HANDLER(ZEND_OPCODE_HANDLER_
                        INIT_PZVAL_COPY(copy, key);
 
                        /* Temporary variables don't need ctor copying */
-                       if (!0) {
+                       if (!1) {
                                zval_copy_ctor(copy);
                        }
 
@@ -9553,7 +9553,7 @@ static int ZEND_FASTCALL  ZEND_YIELD_SPEC_TMP_CONST_HANDLER(ZEND_OPCODE_HANDLER_
                        INIT_PZVAL_COPY(copy, key);
 
                        /* Temporary variables don't need ctor copying */
-                       if (!1) {
+                       if (!0) {
                                zval_copy_ctor(copy);
                        }
 
@@ -11266,7 +11266,7 @@ static int ZEND_FASTCALL  ZEND_YIELD_SPEC_TMP_VAR_HANDLER(ZEND_OPCODE_HANDLER_AR
                        INIT_PZVAL_COPY(copy, key);
 
                        /* Temporary variables don't need ctor copying */
-                       if (!1) {
+                       if (!0) {
                                zval_copy_ctor(copy);
                        }
 
@@ -11846,7 +11846,7 @@ static int ZEND_FASTCALL  ZEND_YIELD_SPEC_TMP_UNUSED_HANDLER(ZEND_OPCODE_HANDLER
                        INIT_PZVAL_COPY(copy, key);
 
                        /* Temporary variables don't need ctor copying */
-                       if (!1) {
+                       if (!0) {
                                zval_copy_ctor(copy);
                        }
 
@@ -12537,7 +12537,7 @@ static int ZEND_FASTCALL  ZEND_YIELD_SPEC_TMP_CV_HANDLER(ZEND_OPCODE_HANDLER_ARG
                        INIT_PZVAL_COPY(copy, key);
 
                        /* Temporary variables don't need ctor copying */
-                       if (!1) {
+                       if (!0) {
                                zval_copy_ctor(copy);
                        }
 
@@ -18543,7 +18543,7 @@ static int ZEND_FASTCALL  ZEND_YIELD_SPEC_VAR_TMP_HANDLER(ZEND_OPCODE_HANDLER_AR
                        INIT_PZVAL_COPY(copy, key);
 
                        /* Temporary variables don't need ctor copying */
-                       if (!0) {
+                       if (!1) {
                                zval_copy_ctor(copy);
                        }
 
@@ -27081,7 +27081,7 @@ static int ZEND_FASTCALL  ZEND_YIELD_SPEC_UNUSED_TMP_HANDLER(ZEND_OPCODE_HANDLER
                        INIT_PZVAL_COPY(copy, key);
 
                        /* Temporary variables don't need ctor copying */
-                       if (!0) {
+                       if (!1) {
                                zval_copy_ctor(copy);
                        }
 
@@ -35600,7 +35600,7 @@ static int ZEND_FASTCALL  ZEND_YIELD_SPEC_CV_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARG
                        INIT_PZVAL_COPY(copy, key);
 
                        /* Temporary variables don't need ctor copying */
-                       if (!0) {
+                       if (!1) {
                                zval_copy_ctor(copy);
                        }