aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYoichi Hirai <i@yoichihirai.com>2017-03-08 19:24:22 +0800
committerGitHub <noreply@github.com>2017-03-08 19:24:22 +0800
commit78f7dd23446fb0bd4bff1847d560df4fac0e1159 (patch)
tree03ba2994c1723ae1d8b88d033230c4ae0a1e3ec7
parent85411f4f677769f3ea1b69c49c44d9c08180dbd4 (diff)
parentd3ab59dff679300ef220e551a28eba20172946d7 (diff)
downloaddexon-solidity-78f7dd23446fb0bd4bff1847d560df4fac0e1159.tar
dexon-solidity-78f7dd23446fb0bd4bff1847d560df4fac0e1159.tar.gz
dexon-solidity-78f7dd23446fb0bd4bff1847d560df4fac0e1159.tar.bz2
dexon-solidity-78f7dd23446fb0bd4bff1847d560df4fac0e1159.tar.lz
dexon-solidity-78f7dd23446fb0bd4bff1847d560df4fac0e1159.tar.xz
dexon-solidity-78f7dd23446fb0bd4bff1847d560df4fac0e1159.tar.zst
dexon-solidity-78f7dd23446fb0bd4bff1847d560df4fac0e1159.zip
Merge pull request #1750 from ethereum/asmoctal
Disallow octal numbers in parser.
-rw-r--r--Changelog.md1
-rw-r--r--docs/types.rst5
-rw-r--r--libsolidity/parsing/Scanner.cpp3
-rw-r--r--test/libsolidity/SolidityScanner.cpp18
4 files changed, 24 insertions, 3 deletions
diff --git a/Changelog.md b/Changelog.md
index ebd6f121..178bd39f 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -10,6 +10,7 @@ Features:
Bugfixes:
* Commandline interface: Always escape filenames (replace ``/``, ``:`` and ``.`` with ``_``).
* Commandline interface: Do not try creating paths ``.`` and ``..``.
+ * Parser: Disallow octal literals.
* Type system: Fix a crash caused by continuing on fatal errors in the code.
* Type system: Detect cyclic dependencies between constants.
* Type system: Disallow arrays with negative length.
diff --git a/docs/types.rst b/docs/types.rst
index f7d1d54f..f89a8ee5 100644
--- a/docs/types.rst
+++ b/docs/types.rst
@@ -197,10 +197,9 @@ Rational and Integer Literals
Integer literals are formed from a sequence of numbers in the range 0-9.
They are interpreted as decimals. For example, ``69`` means sixty nine.
-Octal literals do not exist in Solidity and leading zeros are ignored.
-For example, ``0100`` means one hundred.
+Octal literals do not exist in Solidity and leading zeros are invalid.
-Decimal literals are formed by a ``.`` with at least one number on
+Decimal fraction literals are formed by a ``.`` with at least one number on
one side. Examples include ``1.``, ``.1`` and ``1.3``.
Number literal expressions retain arbitrary precision until they are converted to a non-literal type (i.e. by
diff --git a/libsolidity/parsing/Scanner.cpp b/libsolidity/parsing/Scanner.cpp
index 3623f23f..0e60fd0b 100644
--- a/libsolidity/parsing/Scanner.cpp
+++ b/libsolidity/parsing/Scanner.cpp
@@ -758,6 +758,9 @@ Token::Value Scanner::scanNumber(char _charSeen)
while (isHexDigit(m_char))
addLiteralCharAndAdvance();
}
+ else if (isDecimalDigit(m_char))
+ // We do not allow octal numbers
+ return Token::Illegal;
}
// Parse decimal digits and allow trailing fractional part.
if (kind == DECIMAL)
diff --git a/test/libsolidity/SolidityScanner.cpp b/test/libsolidity/SolidityScanner.cpp
index eb2f042c..3a5c6f24 100644
--- a/test/libsolidity/SolidityScanner.cpp
+++ b/test/libsolidity/SolidityScanner.cpp
@@ -97,6 +97,24 @@ BOOST_AUTO_TEST_CASE(hex_numbers)
BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
}
+BOOST_AUTO_TEST_CASE(octal_numbers)
+{
+ Scanner scanner(CharStream("07"));
+ BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Illegal);
+ scanner.reset(CharStream("007"), "");
+ BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Illegal);
+ scanner.reset(CharStream("-07"), "");
+ BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Sub);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
+ scanner.reset(CharStream("-.07"), "");
+ BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Sub);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::Number);
+ scanner.reset(CharStream("0"), "");
+ BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Number);
+ scanner.reset(CharStream("0.1"), "");
+ BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Number);
+}
+
BOOST_AUTO_TEST_CASE(negative_numbers)
{
Scanner scanner(CharStream("var x = -.2 + -0x78 + -7.3 + 8.9;"));