diff options
author | chriseth <chris@ethereum.org> | 2018-09-20 17:07:56 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-20 17:07:56 +0800 |
commit | 28c9b5db6ab709c734c16da5e3a9da5cfb6f67e5 (patch) | |
tree | 8336b35a1cac5a667a27c64c259b398c94626a8f | |
parent | 2150aea344c259eb6541cb3617e7ae0f3d3381dd (diff) | |
parent | b409faa675be96dda961b14eca9adde62be63263 (diff) | |
download | dexon-solidity-28c9b5db6ab709c734c16da5e3a9da5cfb6f67e5.tar.gz dexon-solidity-28c9b5db6ab709c734c16da5e3a9da5cfb6f67e5.tar.zst dexon-solidity-28c9b5db6ab709c734c16da5e3a9da5cfb6f67e5.zip |
Merge pull request #5011 from hydai/disallow_uppercase_x
Disallow uppercase X in hex number literals
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | docs/grammar.txt | 2 | ||||
-rw-r--r-- | libsolidity/parsing/Scanner.cpp | 4 | ||||
-rw-r--r-- | test/libsolidity/SolidityScanner.cpp | 5 |
4 files changed, 9 insertions, 3 deletions
diff --git a/Changelog.md b/Changelog.md index 7443a0c6..21de2ce6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -41,6 +41,7 @@ Breaking Changes: * Optimizer: Remove the no-op ``PUSH1 0 NOT AND`` sequence. * Parser: Disallow trailing dots that are not followed by a number. * Parser: Remove ``constant`` as function state mutability modifier. + * Parser: Disallow uppercase X in hex number literals * Type Checker: Disallow assignments between tuples with different numbers of components. This was already the case in the experimental 0.5.0 mode. * Type Checker: Disallow values for constants that are not compile-time constants. This was already the case in the experimental 0.5.0 mode. * Type Checker: Disallow arithmetic operations for boolean variables. diff --git a/docs/grammar.txt b/docs/grammar.txt index 594998f0..b9c8ddb9 100644 --- a/docs/grammar.txt +++ b/docs/grammar.txt @@ -132,7 +132,7 @@ HexLiteral = 'hex' ('"' ([0-9a-fA-F]{2})* '"' | '\'' ([0-9a-fA-F]{2})* '\'') StringLiteral = '"' ([^"\r\n\\] | '\\' .)* '"' Identifier = [a-zA-Z_$] [a-zA-Z_$0-9]* -HexNumber = '0' [xX] [0-9a-fA-F]+ +HexNumber = '0x' [0-9a-fA-F]+ DecimalNumber = [0-9]+ ( '.' [0-9]* )? ( [eE] [0-9]+ )? TupleExpression = '(' ( Expression? ( ',' Expression? )* )? ')' diff --git a/libsolidity/parsing/Scanner.cpp b/libsolidity/parsing/Scanner.cpp index c9d5b969..0f6d6996 100644 --- a/libsolidity/parsing/Scanner.cpp +++ b/libsolidity/parsing/Scanner.cpp @@ -780,13 +780,13 @@ Token::Value Scanner::scanNumber(char _charSeen) { addLiteralCharAndAdvance(); // either 0, 0exxx, 0Exxx, 0.xxx or a hex number - if (m_char == 'x' || m_char == 'X') + if (m_char == 'x') { // hex number kind = HEX; addLiteralCharAndAdvance(); if (!isHexDigit(m_char)) - return Token::Illegal; // we must have at least one hex digit after 'x'/'X' + return Token::Illegal; // we must have at least one hex digit after 'x' while (isHexDigit(m_char) || m_char == '_') // We keep the underscores for later validation addLiteralCharAndAdvance(); diff --git a/test/libsolidity/SolidityScanner.cpp b/test/libsolidity/SolidityScanner.cpp index 3a210f94..93db236b 100644 --- a/test/libsolidity/SolidityScanner.cpp +++ b/test/libsolidity/SolidityScanner.cpp @@ -105,6 +105,11 @@ BOOST_AUTO_TEST_CASE(hex_numbers) BOOST_CHECK_EQUAL(scanner.currentLiteral(), "0x765432536763762734623472346"); BOOST_CHECK_EQUAL(scanner.next(), Token::Semicolon); BOOST_CHECK_EQUAL(scanner.next(), Token::EOS); + scanner.reset(CharStream("0x1234"), ""); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Number); + BOOST_CHECK_EQUAL(scanner.currentLiteral(), "0x1234"); + scanner.reset(CharStream("0X1234"), ""); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Illegal); } BOOST_AUTO_TEST_CASE(octal_numbers) |