From b533df36436432def2e8c14099b0cf98f96ff839 Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Sat, 17 Jun 2023 00:32:38 -0400 Subject: Prevent invalid iterator dereference gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::classify_keyword): Check if iterator is valid before dereferencing. Signed-off-by: Owen Avery --- gcc/rust/lex/rust-lex.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gcc') diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index d80ce9a..b1a867b 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -255,11 +255,12 @@ TokenId Lexer::classify_keyword (const std::string &str) { auto keyword = keywords.find (str); - auto id = keyword->second; if (keyword == keywords.end ()) return IDENTIFIER; + auto id = keyword->second; + // We now have the expected token ID of the reserved keyword. However, some // keywords are reserved starting in certain editions. For example, `try` is // only a reserved keyword in editions >=2018. The language might gain new -- cgit v1.1