From 3b2ce130b6ea810e881bac3cc9c0ba24a6d03314 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Wed, 27 Jul 2022 22:54:50 +0000 Subject: [PATCH] Stay within lex'd token bounds. If we've walked to the end of the list, make sure we don't advance past the EOF or Error tokens. Bug: 1347943 Change-Id: I79c9254c39747cc0fb236ae92f8a0f3aa035a932 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97460 Auto-Submit: Dan Sinclair Reviewed-by: Ben Clayton Commit-Queue: Dan Sinclair Kokoro: Kokoro --- src/tint/reader/wgsl/parser_impl.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/tint/reader/wgsl/parser_impl.cc b/src/tint/reader/wgsl/parser_impl.cc index b449e31db4..3adab59cc1 100644 --- a/src/tint/reader/wgsl/parser_impl.cc +++ b/src/tint/reader/wgsl/parser_impl.cc @@ -248,7 +248,11 @@ const Token& ParserImpl::next() { next_token_idx_++; } last_source_idx_ = next_token_idx_; - return tokens_[next_token_idx_++]; + + if (!tokens_[next_token_idx_].IsEof() && !tokens_[next_token_idx_].IsError()) { + next_token_idx_++; + } + return tokens_[last_source_idx_]; } const Token& ParserImpl::peek(size_t idx) { @@ -263,6 +267,9 @@ const Token& ParserImpl::peek(size_t idx) { } idx++; } + if (next_token_idx_ + idx >= tokens_.size()) { + return tokens_[tokens_.size() - 1]; + } return tokens_[next_token_idx_ + idx]; }