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

Unified Diff: tools/gn/parse_tree.cc

Issue 1038233002: tools/gn: disallow non-canonical integer literals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move kBad tests down by usage Created 5 years, 9 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 | tools/gn/parse_tree_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/parse_tree.cc
diff --git a/tools/gn/parse_tree.cc b/tools/gn/parse_tree.cc
index f5897065548f01b102328c3edaa41a7f31a27af6..5e5b9ea01b719b1e5f1ca69fe06868dd570c74a3 100644
--- a/tools/gn/parse_tree.cc
+++ b/tools/gn/parse_tree.cc
@@ -634,8 +634,16 @@ Value LiteralNode::Execute(Scope* scope, Err* err) const {
case Token::FALSE_TOKEN:
return Value(this, false);
case Token::INTEGER: {
+ base::StringPiece s = value_.value();
+ if ((s.starts_with("0") && s.size() > 1) || s.starts_with("-0")) {
+ if (s == "-0")
+ *err = MakeErrorDescribing("Negative zero doesn't make sense");
+ else
+ *err = MakeErrorDescribing("Leading zeros not allowed");
+ return Value();
+ }
int64 result_int;
- if (!base::StringToInt64(value_.value(), &result_int)) {
+ if (!base::StringToInt64(s, &result_int)) {
*err = MakeErrorDescribing("This does not look like an integer");
return Value();
}
« no previous file with comments | « no previous file | tools/gn/parse_tree_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698