authorgravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2018-08-31 23:17:17+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2018-08-31 23:17:17+02:00
loge036f65ac0df91b03dc6bcda8b043484321c6857
tree4abc30c75651f59ca7cce254300b30f388444ade
parent9de0f900e1a80554ac72c8675fc2896977f4930b
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Translate-c: Check for error before working on while loop body (#1445)


1 files changed, 10 insertions(+), 11 deletions(-)

src/translate_c.cpp+10-11
......@@ -3023,12 +3023,19 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const Stmt *stmt,
30233023 trans_unary_operator(c, result_used, scope, (const UnaryOperator *)stmt));
30243024 case Stmt::DeclStmtClass:
30253025 return trans_local_declaration(c, scope, (const DeclStmt *)stmt, out_node, out_child_scope);
3026 case Stmt::DoStmtClass:
30263027 case Stmt::WhileStmtClass: {
3027 AstNode *while_node = trans_while_loop(c, scope, (const WhileStmt *)stmt);
3028 AstNode *while_node = sc == Stmt::DoStmtClass
3029 ? trans_do_loop(c, scope, (const DoStmt *)stmt)
3030 : trans_while_loop(c, scope, (const WhileStmt *)stmt);
3031
3032 if (while_node == nullptr)
3033 return ErrorUnexpected;
3034
30283035 assert(while_node->type == NodeTypeWhileExpr);
3029 if (while_node->data.while_expr.body == nullptr) {
3036 if (while_node->data.while_expr.body == nullptr)
30303037 while_node->data.while_expr.body = trans_create_node(c, NodeTypeBlock);
3031 }
3038
30323039 return wrap_stmt(out_node, out_child_scope, scope, while_node);
30333040 }
30343041 case Stmt::IfStmtClass:
......@@ -3053,14 +3060,6 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const Stmt *stmt,
30533060 case Stmt::UnaryExprOrTypeTraitExprClass:
30543061 return wrap_stmt(out_node, out_child_scope, scope,
30553062 trans_unary_expr_or_type_trait_expr(c, scope, (const UnaryExprOrTypeTraitExpr *)stmt));
3056 case Stmt::DoStmtClass: {
3057 AstNode *while_node = trans_do_loop(c, scope, (const DoStmt *)stmt);
3058 assert(while_node->type == NodeTypeWhileExpr);
3059 if (while_node->data.while_expr.body == nullptr) {
3060 while_node->data.while_expr.body = trans_create_node(c, NodeTypeBlock);
3061 }
3062 return wrap_stmt(out_node, out_child_scope, scope, while_node);
3063 }
30643063 case Stmt::ForStmtClass: {
30653064 AstNode *node = trans_for_loop(c, scope, (const ForStmt *)stmt);
30663065 return wrap_stmt(out_node, out_child_scope, scope, node);