Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Unified Diff: tools/gn/parser.cc

Issue 2282493002: gn: Don't do an out-of-bound access if a file ends after 'else' (Closed)
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/parser.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/parser.cc
diff --git a/tools/gn/parser.cc b/tools/gn/parser.cc
index 57a398e0187e50f03a7efa15443009fc9efb41ab..41ee6b61c389fd50dd430163605a1045f9030c30 100644
--- a/tools/gn/parser.cc
+++ b/tools/gn/parser.cc
@@ -388,7 +388,8 @@ Token Parser::Consume(Token::Type* types,
if (has_error()) {
// Don't overwrite current error, but make progress through tokens so that
// a loop that's expecting a particular token will still terminate.
- cur_++;
+ if (!at_end())
Nico 2016/08/25 16:07:49 this is unrelated but seems like a good change so
+ cur_++;
return Token(Location(), Token::INVALID, base::StringPiece());
}
if (at_end()) {
@@ -708,7 +709,7 @@ std::unique_ptr<ParseNode> Parser::ParseStatement() {
return stmt;
}
if (!has_error()) {
- Token token = at_end() ? tokens_[tokens_.size() - 1] : cur_token();
+ Token token = cur_or_last_token();
Nico 2016/08/25 16:07:49 this is just extract-function
*err_ = Err(token, "Expecting assignment or function call.");
}
return std::unique_ptr<ParseNode>();
@@ -755,7 +756,7 @@ std::unique_ptr<ParseNode> Parser::ParseCondition() {
} else if (LookAhead(Token::IF)) {
condition->set_if_false(ParseStatement());
} else {
- *err_ = Err(cur_token(), "Expected '{' or 'if' after 'else'.");
+ *err_ = Err(cur_or_last_token(), "Expected '{' or 'if' after 'else'.");
Nico 2016/08/25 16:07:49 this is the fix
return std::unique_ptr<ParseNode>();
}
}
« no previous file with comments | « tools/gn/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698