From e8e5e12ad29004714f04f3697a6fdfb7813602c1 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Wed, 11 Jul 2018 15:30:54 +0200 Subject: [PATCH] Fix literals with exponents with mantissa of zero. --- libsolidity/ast/Types.cpp | 19 +++++++++++-------- .../types/rational_number_exp_limit.sol | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 0a4f199dd..dd0736e95 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -771,7 +771,17 @@ tuple RationalNumberType::isValidLiteral(Literal const& _literal } else if (expPoint != _literal.value().end()) { - // Parse base and exponent. Checks numeric limit. + // Parse mantissa and exponent. Checks numeric limit. + tuple mantissa = parseRational(string(_literal.value().begin(), expPoint)); + + if (!get<0>(mantissa)) + return make_tuple(false, rational(0)); + value = get<1>(mantissa); + + // 0E... is always zero. + if (value == 0) + return make_tuple(true, rational(0)); + bigint exp = bigint(string(expPoint + 1, _literal.value().end())); if (exp > numeric_limits::max() || exp < numeric_limits::min()) @@ -779,13 +789,6 @@ tuple RationalNumberType::isValidLiteral(Literal const& _literal uint32_t expAbs = bigint(abs(exp)).convert_to(); - - tuple base = parseRational(string(_literal.value().begin(), expPoint)); - - if (!get<0>(base)) - return make_tuple(false, rational(0)); - value = get<1>(base); - if (exp < 0) { if (!fitsPrecisionBase10(abs(value.denominator()), expAbs)) diff --git a/test/libsolidity/syntaxTests/types/rational_number_exp_limit.sol b/test/libsolidity/syntaxTests/types/rational_number_exp_limit.sol index 6785f580a..217122055 100644 --- a/test/libsolidity/syntaxTests/types/rational_number_exp_limit.sol +++ b/test/libsolidity/syntaxTests/types/rational_number_exp_limit.sol @@ -19,6 +19,7 @@ contract c { a = 1E1233 ** -1E1233; a = -1E1233 ** 1E1233; a = -1E1233 ** -1E1233; + a = 0E123456789; // fine } } // ----