aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Kirchner <daniel@ekpyron.org>2018-07-11 21:30:54 +0800
committerDaniel Kirchner <daniel@ekpyron.org>2018-07-11 21:34:17 +0800
commite8e5e12ad29004714f04f3697a6fdfb7813602c1 (patch)
tree867c7167b2091148bf0fb5797a8e2320704dd263
parentf3abfa81ad3cdf3cfd0b9e1acf11329a617466a2 (diff)
downloaddexon-solidity-e8e5e12ad29004714f04f3697a6fdfb7813602c1.tar
dexon-solidity-e8e5e12ad29004714f04f3697a6fdfb7813602c1.tar.gz
dexon-solidity-e8e5e12ad29004714f04f3697a6fdfb7813602c1.tar.bz2
dexon-solidity-e8e5e12ad29004714f04f3697a6fdfb7813602c1.tar.lz
dexon-solidity-e8e5e12ad29004714f04f3697a6fdfb7813602c1.tar.xz
dexon-solidity-e8e5e12ad29004714f04f3697a6fdfb7813602c1.tar.zst
dexon-solidity-e8e5e12ad29004714f04f3697a6fdfb7813602c1.zip
Fix literals with exponents with mantissa of zero.
-rw-r--r--libsolidity/ast/Types.cpp19
-rw-r--r--test/libsolidity/syntaxTests/types/rational_number_exp_limit.sol1
2 files changed, 12 insertions, 8 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index 0a4f199d..dd0736e9 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -771,20 +771,23 @@ tuple<bool, rational> RationalNumberType::isValidLiteral(Literal const& _literal
}
else if (expPoint != _literal.value().end())
{
- // Parse base and exponent. Checks numeric limit.
- bigint exp = bigint(string(expPoint + 1, _literal.value().end()));
+ // Parse mantissa and exponent. Checks numeric limit.
+ tuple<bool, rational> mantissa = parseRational(string(_literal.value().begin(), expPoint));
- if (exp > numeric_limits<int32_t>::max() || exp < numeric_limits<int32_t>::min())
+ if (!get<0>(mantissa))
return make_tuple(false, rational(0));
+ value = get<1>(mantissa);
- uint32_t expAbs = bigint(abs(exp)).convert_to<uint32_t>();
-
+ // 0E... is always zero.
+ if (value == 0)
+ return make_tuple(true, rational(0));
- tuple<bool, rational> base = parseRational(string(_literal.value().begin(), expPoint));
+ bigint exp = bigint(string(expPoint + 1, _literal.value().end()));
- if (!get<0>(base))
+ if (exp > numeric_limits<int32_t>::max() || exp < numeric_limits<int32_t>::min())
return make_tuple(false, rational(0));
- value = get<1>(base);
+
+ uint32_t expAbs = bigint(abs(exp)).convert_to<uint32_t>();
if (exp < 0)
{
diff --git a/test/libsolidity/syntaxTests/types/rational_number_exp_limit.sol b/test/libsolidity/syntaxTests/types/rational_number_exp_limit.sol
index 6785f580..21712205 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
}
}
// ----