]> granicus.if.org Git - php/commitdiff
Don't alloc empty jmp opnum list for single-branch if
authorNikita Popov <nikic@php.net>
Tue, 26 Aug 2014 17:39:40 +0000 (19:39 +0200)
committerNikita Popov <nikic@php.net>
Tue, 26 Aug 2014 20:31:57 +0000 (22:31 +0200)
Zend/zend_compile.c

index 5e2455960b144c47533b2c4a807bc9e975cbc5b6..15edc7c3804fcf5e3cb2a8ebf96fa769904fcc17 100644 (file)
@@ -4897,7 +4897,11 @@ void zend_compile_foreach(zend_ast *ast TSRMLS_DC) {
 void zend_compile_if(zend_ast *ast TSRMLS_DC) {
        zend_ast_list *list = zend_ast_get_list(ast);
        uint32_t i;
-       uint32_t *jmp_opnums = safe_emalloc(sizeof(uint32_t), list->children - 1, 0);
+       uint32_t *jmp_opnums;
+       
+       if (list->children > 1) {
+               jmp_opnums = safe_emalloc(sizeof(uint32_t), list->children - 1, 0);
+       }
 
        for (i = 0; i < list->children; ++i) {
                zend_ast *elem_ast = list->child[i];
@@ -4922,11 +4926,12 @@ void zend_compile_if(zend_ast *ast TSRMLS_DC) {
                }
        }
 
-       for (i = 0; i < list->children - 1; ++i) {
-               zend_update_jump_target_to_next(jmp_opnums[i] TSRMLS_CC);
+       if (list->children > 1) {
+               for (i = 0; i < list->children - 1; ++i) {
+                       zend_update_jump_target_to_next(jmp_opnums[i] TSRMLS_CC);
+               }
+               efree(jmp_opnums);
        }
-
-       efree(jmp_opnums);
 }
 
 void zend_compile_switch(zend_ast *ast TSRMLS_DC) {