diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-08-04 12:34:29 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-04 12:34:29 +0000 |
commit | 7bdd8599b99a80b5930945bb87d1abffba8ee157 (patch) | |
tree | 35177429e31831ef2af9c154b0cb03c514850da8 /gcc/rust/parse/rust-parse-impl.h | |
parent | 73271c4ce5d33fe51766ce9cc438cad764bf31c1 (diff) | |
parent | 0209c8f6624a287a2e23bfbce70e8729947c43be (diff) | |
download | gcc-7bdd8599b99a80b5930945bb87d1abffba8ee157.zip gcc-7bdd8599b99a80b5930945bb87d1abffba8ee157.tar.gz gcc-7bdd8599b99a80b5930945bb87d1abffba8ee157.tar.bz2 |
Merge #606
606: Always check the result of expect_token while parsing r=dkm a=dkm
From Mark Wielaard : https://gcc.gnu.org/pipermail/gcc-rust/2021-August/000111.html
> When expect_token fails it produces an error and return a
> nullptr. Make sure to always check the result of expect_token so we
> don't use a nullptr token and crash.
>
> Resolves: https://github.com/Rust-GCC/gccrs/issues/603
Co-authored-by: Mark Wielaard <mark@klomp.org>
Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
Diffstat (limited to 'gcc/rust/parse/rust-parse-impl.h')
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 9eb212b..acc9d06 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -1898,6 +1898,9 @@ Parser<ManagedTokenSource>::parse_macro_match_fragment () // get MacroFragSpec for macro const_TokenPtr t = expect_token (IDENTIFIER); + if (t == nullptr) + return nullptr; + AST::MacroFragSpec frag = AST::get_frag_spec_from_str (t->get_str ()); if (frag == AST::INVALID) { @@ -4325,6 +4328,9 @@ Parser<ManagedTokenSource>::parse_enum (AST::Visibility vis, // parse enum name const_TokenPtr enum_name_tok = expect_token (IDENTIFIER); + if (enum_name_tok == nullptr) + return nullptr; + Identifier enum_name = enum_name_tok->get_str (); // parse generic params (of enum container, not enum variants) if they exist @@ -4650,6 +4656,9 @@ Parser<ManagedTokenSource>::parse_static_item (AST::Visibility vis, } const_TokenPtr ident_tok = expect_token (IDENTIFIER); + if (ident_tok == nullptr) + return nullptr; + Identifier ident = ident_tok->get_str (); if (!skip_token (COLON)) @@ -4700,6 +4709,9 @@ Parser<ManagedTokenSource>::parse_trait (AST::Visibility vis, // parse trait name const_TokenPtr ident_tok = expect_token (IDENTIFIER); + if (ident_tok == nullptr) + return nullptr; + Identifier ident = ident_tok->get_str (); // parse generic parameters (if they exist) @@ -4805,6 +4817,9 @@ Parser<ManagedTokenSource>::parse_trait_item () // parse function or method name const_TokenPtr ident_tok = expect_token (IDENTIFIER); + if (ident_tok == nullptr) + return nullptr; + Identifier ident = ident_tok->get_str (); // parse generic params @@ -4937,6 +4952,9 @@ Parser<ManagedTokenSource>::parse_trait_type (AST::AttrVec outer_attrs) skip_token (TYPE); const_TokenPtr ident_tok = expect_token (IDENTIFIER); + if (ident_tok == nullptr) + return nullptr; + Identifier ident = ident_tok->get_str (); std::vector<std::unique_ptr<AST::TypeParamBound>> bounds; @@ -4973,6 +4991,9 @@ Parser<ManagedTokenSource>::parse_trait_const (AST::AttrVec outer_attrs) // parse constant item name const_TokenPtr ident_tok = expect_token (IDENTIFIER); + if (ident_tok == nullptr) + return nullptr; + Identifier ident = ident_tok->get_str (); if (!skip_token (COLON)) @@ -5338,6 +5359,9 @@ Parser<ManagedTokenSource>::parse_inherent_impl_function_or_method ( // parse function or method name const_TokenPtr ident_tok = expect_token (IDENTIFIER); + if (ident_tok == nullptr) + return nullptr; + Identifier ident = ident_tok->get_str (); // parse generic params @@ -14210,6 +14234,9 @@ Parser<ManagedTokenSource>::parse_field_access_expr ( /* get field name identifier (assume that this is a field access expr and not * await, for instance) */ const_TokenPtr ident_tok = expect_token (IDENTIFIER); + if (ident_tok == nullptr) + return nullptr; + Identifier ident = ident_tok->get_str (); Location locus = struct_expr->get_locus_slow (); |