diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-08-28 22:07:14 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-28 22:07:14 +0800 |
commit | 1beef3836187fd92499aad80693dc6beb1d3a36f (patch) | |
tree | c5c3095b76adc4bcf4a55a248a9b3728b60fda02 | |
parent | b3c251c1548e8f85a76cf1aef8bb698daa5e5ec7 (diff) | |
parent | 122e65f8f496b0b20406cc968a2e48e6434d1a8f (diff) | |
download | dexon-solidity-1beef3836187fd92499aad80693dc6beb1d3a36f.tar.gz dexon-solidity-1beef3836187fd92499aad80693dc6beb1d3a36f.tar.zst dexon-solidity-1beef3836187fd92499aad80693dc6beb1d3a36f.zip |
Merge pull request #2834 from ethereum/fixTypeNameParsing
Crash fix, parseTypeName can return null.
-rw-r--r-- | Changelog.md | 2 | ||||
-rw-r--r-- | libsolidity/parsing/Parser.cpp | 5 | ||||
-rw-r--r-- | test/libsolidity/SolidityParser.cpp | 12 |
3 files changed, 18 insertions, 1 deletions
diff --git a/Changelog.md b/Changelog.md index 670182af..49855369 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,8 @@ Features: * Type Checker: Warn on using literals as tight packing parameters in ``keccak256``, ``sha3``, ``sha256`` and ``ripemd160``. Bugfixes: + * Parser: Crash fix related to parseTypeName. + ### 0.4.16 (2017-08-24) diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 4fc8fd13..ce8a9f01 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -1244,7 +1244,10 @@ ASTPointer<Expression> Parser::parseLeftHandSideExpression( { expectToken(Token::New); ASTPointer<TypeName> typeName(parseTypeName(false)); - nodeFactory.setEndPositionFromNode(typeName); + if (typeName) + nodeFactory.setEndPositionFromNode(typeName); + else + nodeFactory.markEndPosition(); expression = nodeFactory.createNode<NewExpression>(typeName); } else diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index a39e0958..60ca03c9 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -1602,6 +1602,18 @@ BOOST_AUTO_TEST_CASE(interface) BOOST_CHECK(successParse(text)); } +BOOST_AUTO_TEST_CASE(newInvalidTypeName) +{ + char const* text = R"( + contract C { + function f() { + new var; + } + } + )"; + CHECK_PARSE_ERROR(text, "Expected explicit type name"); +} + BOOST_AUTO_TEST_SUITE_END() } |