aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/parse/rust-parse-impl.h
diff options
context:
space:
mode:
authorMarc Poulhiès <dkm@kataplop.net>2022-10-07 18:48:36 +0200
committerMarc Poulhiès <dkm@kataplop.net>2022-10-08 10:08:20 +0200
commitd4c07a9b47c7063a4e79b6b45edccd0e79249605 (patch)
tree945d1ce4d8a45e0ec32912c8b23883cc02ebb578 /gcc/rust/parse/rust-parse-impl.h
parent06fe912b70bc21dd11e7279e29200431a5b50aa2 (diff)
downloadgcc-d4c07a9b47c7063a4e79b6b45edccd0e79249605.zip
gcc-d4c07a9b47c7063a4e79b6b45edccd0e79249605.tar.gz
gcc-d4c07a9b47c7063a4e79b6b45edccd0e79249605.tar.bz2
fix ICE on missing closing paren
Fix crash (segfault) on a missing closing parenthesis when parsing the expressions in a block. The returned `expr` was missing a check before being used. Add corresponding test. Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Diffstat (limited to 'gcc/rust/parse/rust-parse-impl.h')
-rw-r--r--gcc/rust/parse/rust-parse-impl.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index c4cfbe2..4ebdcf0 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -11728,10 +11728,17 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr_without_block ()
// must be expression statement
lexer.skip_token ();
- std::unique_ptr<AST::ExprStmtWithoutBlock> stmt (
- new AST::ExprStmtWithoutBlock (std::move (expr),
- t->get_locus ()));
- return ExprOrStmt (std::move (stmt));
+ if (expr)
+ {
+ std::unique_ptr<AST::ExprStmtWithoutBlock> stmt (
+ new AST::ExprStmtWithoutBlock (std::move (expr),
+ t->get_locus ()));
+ return ExprOrStmt (std::move (stmt));
+ }
+ else
+ {
+ return ExprOrStmt::create_error ();
+ }
}
// return expression