Merge pull request #2473 from chriseth/sol_fix_exponentialNotation

Check whether a literal is a valid literal before using it.
This commit is contained in:
Gav Wood 2015-07-14 18:18:38 +02:00
commit d747f34466
2 changed files with 18 additions and 0 deletions

View File

@ -210,6 +210,8 @@ TypePointer Type::forLiteral(Literal const& _literal)
case Token::FalseLiteral: case Token::FalseLiteral:
return make_shared<BoolType>(); return make_shared<BoolType>();
case Token::Number: case Token::Number:
if (!IntegerConstantType::isValidLiteral(_literal))
return TypePointer();
return make_shared<IntegerConstantType>(_literal); return make_shared<IntegerConstantType>(_literal);
case Token::StringLiteral: case Token::StringLiteral:
return make_shared<StringLiteralType>(_literal); return make_shared<StringLiteralType>(_literal);
@ -321,6 +323,19 @@ const MemberList IntegerType::AddressMemberList({
{"send", make_shared<FunctionType>(strings{"uint"}, strings{"bool"}, FunctionType::Location::Send)} {"send", make_shared<FunctionType>(strings{"uint"}, strings{"bool"}, FunctionType::Location::Send)}
}); });
bool IntegerConstantType::isValidLiteral(const Literal& _literal)
{
try
{
bigint x(_literal.getValue());
}
catch (...)
{
return false;
}
return true;
}
IntegerConstantType::IntegerConstantType(Literal const& _literal) IntegerConstantType::IntegerConstantType(Literal const& _literal)
{ {
m_value = bigint(_literal.getValue()); m_value = bigint(_literal.getValue());

View File

@ -286,6 +286,9 @@ class IntegerConstantType: public Type
public: public:
virtual Category getCategory() const override { return Category::IntegerConstant; } virtual Category getCategory() const override { return Category::IntegerConstant; }
/// @returns true if the literal is a valid integer.
static bool isValidLiteral(Literal const& _literal);
explicit IntegerConstantType(Literal const& _literal); explicit IntegerConstantType(Literal const& _literal);
explicit IntegerConstantType(bigint _value): m_value(_value) {} explicit IntegerConstantType(bigint _value): m_value(_value) {}