From: lenny.chiadmi-delage Date: Wed, 15 Oct 2025 15:07:05 +0000 (+0000) Subject: gccrs: fix segfault in clone_pattern w macro X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5be67e843c577e322d23885776d0de3ee6d66bd1;p=thirdparty%2Fgcc.git gccrs: fix segfault in clone_pattern w macro Check if parser throw an error to avoid cloning nullptr Fixes Rust-GCC#4140 gcc/rust/ChangeLog: * expand/rust-macro-expand.cc (transcribe_expression): Check if parser didn't fail. (transcribe_type): Likewise. (transcribe_pattern): Likewise. Signed-off-by: lenny.chiadmi-delage --- diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index 52f8e2b10e3..b47e43afd76 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -962,12 +962,10 @@ transcribe_expression (Parser &parser) auto attrs = parser.parse_outer_attributes (); auto expr = parser.parse_expr (std::move (attrs)); - if (expr == nullptr) - { - for (auto error : parser.get_errors ()) - error.emit (); - return AST::Fragment::create_error (); - } + for (auto error : parser.get_errors ()) + error.emit (); + if (!expr) + return AST::Fragment::create_error (); // FIXME: make this an error for some edititons if (parser.peek_current_token ()->get_id () == SEMICOLON) @@ -997,6 +995,8 @@ transcribe_type (Parser &parser) auto type = parser.parse_type (true); for (auto err : parser.get_errors ()) err.emit (); + if (!type) + return AST::Fragment::create_error (); auto end = lexer.get_offs (); @@ -1018,6 +1018,9 @@ transcribe_pattern (Parser &parser) for (auto err : parser.get_errors ()) err.emit (); + if (!pattern) + return AST::Fragment::create_error (); + auto end = lexer.get_offs (); return AST::Fragment ({std::move (pattern)},