Skip to content

Commit b533df3

Browse files
powerboat9CohenArthur
authored andcommitted
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 <[email protected]>
1 parent 7671253 commit b533df3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

gcc/rust/lex/rust-lex.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,12 @@ TokenId
255255
Lexer::classify_keyword (const std::string &str)
256256
{
257257
auto keyword = keywords.find (str);
258-
auto id = keyword->second;
259258

260259
if (keyword == keywords.end ())
261260
return IDENTIFIER;
262261

262+
auto id = keyword->second;
263+
263264
// We now have the expected token ID of the reserved keyword. However, some
264265
// keywords are reserved starting in certain editions. For example, `try` is
265266
// only a reserved keyword in editions >=2018. The language might gain new

0 commit comments

Comments
 (0)