Skip to content

Commit 653fd33

Browse files
committed
Fix segfault
1 parent 5532fdf commit 653fd33

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

src/cc/frontend/parser.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,8 @@ static Stmt *parse_stmt(void) {
676676

677677
// expression statement.
678678
Expr *val = parse_expr();
679+
if (val == NULL)
680+
val = new_expr_fixlit(&tyInt, tok, 0); // Dummy
679681
consume(TK_SEMICOL, "`;' expected");
680682
return new_stmt_expr(str_to_char_array_var(curscope, val));
681683
}

src/cc/frontend/parser_expr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,8 @@ Expr *parse_assign(void) {
825825
Expr *parse_const_fixnum(void) {
826826
parsing_stmt = false;
827827
Expr *expr = parse_precedence(PREC_LOGIOR);
828+
if (expr == NULL)
829+
return NULL; // Error is already reported.
828830
if (is_const(expr) && is_fixnum(expr->type->kind))
829831
return expr;
830832
parse_error(PE_NOFATAL, expr->token, "constant integer expected");

0 commit comments

Comments
 (0)