Skip to content

Commit 9a159f3

Browse files
committed
Improved GENERATOR_CREATE opcode handler.
1 parent c2f25bd commit 9a159f3

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ PHP NEWS
33
?? ??? 2017, PHP 7.1.2
44

55
- Core:
6+
. Improved GENERATOR_CREATE opcode handler. (Bob, Dmitry)
67
. Fixed bug #73877 (readlink() returns garbage for UTF-8 paths). (Anatol)
78
. Fixed bug #73876 (Crash when exporting **= in expansion of assign op).
89
(Sara)

Zend/zend_vm_def.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4093,8 +4093,14 @@ ZEND_VM_HANDLER(41, ZEND_GENERATOR_CREATE, ANY, ANY)
40934093
* is allocated on heap.
40944094
*/
40954095
num_args = EX_NUM_ARGS();
4096-
used_stack = (ZEND_CALL_FRAME_SLOT + num_args + EX(func)->op_array.last_var + EX(func)->op_array.T - MIN(EX(func)->op_array.num_args, num_args)) * sizeof(zval);
4097-
gen_execute_data = (zend_execute_data*)emalloc(used_stack);
4096+
if (EXPECTED(num_args <= EX(func)->op_array.last_var)) {
4097+
used_stack = (ZEND_CALL_FRAME_SLOT + EX(func)->op_array.last_var + EX(func)->op_array.T) * sizeof(zval);
4098+
gen_execute_data = (zend_execute_data*)emalloc(used_stack);
4099+
used_stack = (ZEND_CALL_FRAME_SLOT + EX(func)->op_array.last_var) * sizeof(zval);
4100+
} else {
4101+
used_stack = (ZEND_CALL_FRAME_SLOT + num_args + EX(func)->op_array.last_var + EX(func)->op_array.T - EX(func)->op_array.num_args) * sizeof(zval);
4102+
gen_execute_data = (zend_execute_data*)emalloc(used_stack);
4103+
}
40984104
memcpy(gen_execute_data, execute_data, used_stack);
40994105

41004106
/* Save execution context in generator object. */

Zend/zend_vm_execute.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,8 +1179,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GENERATOR_CREATE_SPEC_HANDLER(
11791179
* is allocated on heap.
11801180
*/
11811181
num_args = EX_NUM_ARGS();
1182-
used_stack = (ZEND_CALL_FRAME_SLOT + num_args + EX(func)->op_array.last_var + EX(func)->op_array.T - MIN(EX(func)->op_array.num_args, num_args)) * sizeof(zval);
1183-
gen_execute_data = (zend_execute_data*)emalloc(used_stack);
1182+
if (EXPECTED(num_args <= EX(func)->op_array.last_var)) {
1183+
used_stack = (ZEND_CALL_FRAME_SLOT + EX(func)->op_array.last_var + EX(func)->op_array.T) * sizeof(zval);
1184+
gen_execute_data = (zend_execute_data*)emalloc(used_stack);
1185+
used_stack = (ZEND_CALL_FRAME_SLOT + EX(func)->op_array.last_var) * sizeof(zval);
1186+
} else {
1187+
used_stack = (ZEND_CALL_FRAME_SLOT + num_args + EX(func)->op_array.last_var + EX(func)->op_array.T - EX(func)->op_array.num_args) * sizeof(zval);
1188+
gen_execute_data = (zend_execute_data*)emalloc(used_stack);
1189+
}
11841190
memcpy(gen_execute_data, execute_data, used_stack);
11851191

11861192
/* Save execution context in generator object. */

0 commit comments

Comments
 (0)