mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #123 from chriseth/largeHexConstants
Check invalid integer constants for functions accepting arbitrary arguments.
This commit is contained in:
commit
b4f817d9d9
@ -824,10 +824,15 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
|
|||||||
{
|
{
|
||||||
// call by positional arguments
|
// call by positional arguments
|
||||||
for (size_t i = 0; i < arguments.size(); ++i)
|
for (size_t i = 0; i < arguments.size(); ++i)
|
||||||
if (
|
{
|
||||||
!functionType->takesArbitraryParameters() &&
|
auto const& argType = type(*arguments[i]);
|
||||||
!type(*arguments[i])->isImplicitlyConvertibleTo(*parameterTypes[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(
|
typeError(
|
||||||
*arguments[i],
|
*arguments[i],
|
||||||
"Invalid type for argument in function call. "
|
"Invalid type for argument in function call. "
|
||||||
@ -838,6 +843,7 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
|
|||||||
" requested."
|
" requested."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// call by named arguments
|
// call by named arguments
|
||||||
|
@ -54,9 +54,9 @@ parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
sourceUnit = parser.parse(std::make_shared<Scanner>(CharStream(_source)));
|
sourceUnit = parser.parse(std::make_shared<Scanner>(CharStream(_source)));
|
||||||
NameAndTypeResolver resolver({});
|
|
||||||
resolver.registerDeclarations(*sourceUnit);
|
|
||||||
std::shared_ptr<GlobalContext> globalContext = make_shared<GlobalContext>();
|
std::shared_ptr<GlobalContext> globalContext = make_shared<GlobalContext>();
|
||||||
|
NameAndTypeResolver resolver(globalContext->declarations());
|
||||||
|
resolver.registerDeclarations(*sourceUnit);
|
||||||
|
|
||||||
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
|
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
|
||||||
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
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);
|
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)
|
BOOST_AUTO_TEST_CASE(cyclic_binary_dependency)
|
||||||
{
|
{
|
||||||
char const* text = R"(
|
char const* text = R"(
|
||||||
|
Loading…
Reference in New Issue
Block a user