Skip to content

Commit c71ab60

Browse files
committed
Don't alloc empty jmp opnum list for single-branch if
1 parent cd8bbfa commit c71ab60

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Zend/zend_compile.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4897,7 +4897,11 @@ void zend_compile_foreach(zend_ast *ast TSRMLS_DC) {
48974897
void zend_compile_if(zend_ast *ast TSRMLS_DC) {
48984898
zend_ast_list *list = zend_ast_get_list(ast);
48994899
uint32_t i;
4900-
uint32_t *jmp_opnums = safe_emalloc(sizeof(uint32_t), list->children - 1, 0);
4900+
uint32_t *jmp_opnums;
4901+
4902+
if (list->children > 1) {
4903+
jmp_opnums = safe_emalloc(sizeof(uint32_t), list->children - 1, 0);
4904+
}
49014905

49024906
for (i = 0; i < list->children; ++i) {
49034907
zend_ast *elem_ast = list->child[i];
@@ -4922,11 +4926,12 @@ void zend_compile_if(zend_ast *ast TSRMLS_DC) {
49224926
}
49234927
}
49244928

4925-
for (i = 0; i < list->children - 1; ++i) {
4926-
zend_update_jump_target_to_next(jmp_opnums[i] TSRMLS_CC);
4929+
if (list->children > 1) {
4930+
for (i = 0; i < list->children - 1; ++i) {
4931+
zend_update_jump_target_to_next(jmp_opnums[i] TSRMLS_CC);
4932+
}
4933+
efree(jmp_opnums);
49274934
}
4928-
4929-
efree(jmp_opnums);
49304935
}
49314936

49324937
void zend_compile_switch(zend_ast *ast TSRMLS_DC) {

0 commit comments

Comments
 (0)