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

Unified Diff: tools/gn/parser.cc

Issue 2271383003: gn: Don't read unitialized memory on files containing just a comment. (Closed)
Patch Set: _EQ 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 | « no previous file | 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..378a71050aeb940de3f174964c920130519b0e99 100644
--- a/tools/gn/parser.cc
+++ b/tools/gn/parser.cc
@@ -453,7 +453,7 @@ std::unique_ptr<ParseNode> Parser::ParseExpression(int precedence) {
}
std::unique_ptr<ParseNode> Parser::Block(Token token) {
- // This entrypoing into ParseBlock means its part of an expression and we
+ // This entrypoint into ParseBlock means it's part of an expression and we
// always want the result.
return ParseBlock(token, BlockNode::RETURNS_SCOPE);
}
@@ -819,6 +819,10 @@ void Parser::AssignComments(ParseNode* file) {
// Assign line comments to syntax immediately following.
int cur_comment = 0;
for (auto* node : pre) {
+ if (node->GetRange().is_null()) {
+ CHECK_EQ(node, file) << "Only expected on top file node";
+ continue;
+ }
const Location& start = node->GetRange().begin();
while (cur_comment < static_cast<int>(line_comment_tokens_.size())) {
if (start.byte() >= line_comment_tokens_[cur_comment].location().byte()) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698