diff options
author | chriseth <c@ethdev.com> | 2015-10-08 00:20:41 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-10-08 00:20:41 +0800 |
commit | b4f817d9d93d9920b6034e0043ac1abb234b596c (patch) | |
tree | d8bc99b9e865814b9e41fdaa8306088e5479092c | |
parent | ab433c9a788bee31417a52d1574a2c8240004901 (diff) | |
parent | 35de03626f4b3c9a29f14ad635151aed9642370d (diff) | |
download | dexon-solidity-b4f817d9d93d9920b6034e0043ac1abb234b596c.tar dexon-solidity-b4f817d9d93d9920b6034e0043ac1abb234b596c.tar.gz dexon-solidity-b4f817d9d93d9920b6034e0043ac1abb234b596c.tar.bz2 dexon-solidity-b4f817d9d93d9920b6034e0043ac1abb234b596c.tar.lz dexon-solidity-b4f817d9d93d9920b6034e0043ac1abb234b596c.tar.xz dexon-solidity-b4f817d9d93d9920b6034e0043ac1abb234b596c.tar.zst dexon-solidity-b4f817d9d93d9920b6034e0043ac1abb234b596c.zip |
Merge pull request #123 from chriseth/largeHexConstants
Check invalid integer constants for functions accepting arbitrary arguments.
-rw-r--r-- | libsolidity/TypeChecker.cpp | 14 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 15 |
2 files changed, 23 insertions, 6 deletions
diff --git a/libsolidity/TypeChecker.cpp b/libsolidity/TypeChecker.cpp index 4b4fc7f1..5bbbd072 100644 --- a/libsolidity/TypeChecker.cpp +++ b/libsolidity/TypeChecker.cpp @@ -824,10 +824,15 @@ bool TypeChecker::visit(FunctionCall const& _functionCall) { // call by positional arguments for (size_t i = 0; i < arguments.size(); ++i) - if ( - !functionType->takesArbitraryParameters() && - !type(*arguments[i])->isImplicitlyConvertibleTo(*parameterTypes[i]) - ) + { + auto const& argType = type(*arguments[i]); + if (functionType->takesArbitraryParameters()) + { + if (auto t = dynamic_cast<IntegerConstantType const*>(argType.get())) + if (!t->integerType()) + typeError(*arguments[i], "Integer constant too large."); + } + else if (!type(*arguments[i])->isImplicitlyConvertibleTo(*parameterTypes[i])) typeError( *arguments[i], "Invalid type for argument in function call. " @@ -837,6 +842,7 @@ bool TypeChecker::visit(FunctionCall const& _functionCall) parameterTypes[i]->toString() + " requested." ); + } } else { diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 99fdf6d9..b55c92f0 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -54,9 +54,9 @@ parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false) try { sourceUnit = parser.parse(std::make_shared<Scanner>(CharStream(_source))); - NameAndTypeResolver resolver({}); - resolver.registerDeclarations(*sourceUnit); std::shared_ptr<GlobalContext> globalContext = make_shared<GlobalContext>(); + NameAndTypeResolver resolver(globalContext->declarations()); + resolver.registerDeclarations(*sourceUnit); for (ASTPointer<ASTNode> const& node: sourceUnit->nodes()) if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) @@ -2366,6 +2366,17 @@ BOOST_AUTO_TEST_CASE(non_initialized_references) SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text, true), Warning); } +BOOST_AUTO_TEST_CASE(sha3_with_large_integer_constant) +{ + char const* text = R"( + contract c + { + function f() { sha3(2**500); } + } + )"; + SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text), TypeError); +} + BOOST_AUTO_TEST_CASE(cyclic_binary_dependency) { char const* text = R"( |