]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Prevent invalid iterator dereference
authorOwen Avery <powerboat9.gamer@gmail.com>
Sat, 17 Jun 2023 04:32:38 +0000 (00:32 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:46:28 +0000 (18:46 +0100)
gcc/rust/ChangeLog:

* lex/rust-lex.cc
(Lexer::classify_keyword): Check if iterator is valid before dereferencing.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/lex/rust-lex.cc

index c910c7cf83adf897be7c1bdaad317206c6cad62d..23579e519443118b2dc8a6ae44536b3f1eb5a6a6 100644 (file)
@@ -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