aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Parpart <christian@parpart.family>2018-08-08 20:46:17 +0800
committerChristian Parpart <christian@ethereum.org>2018-08-14 21:38:10 +0800
commit43bda534102c95a85daddc64fb466eb8c88e2325 (patch)
tree825f2366d2eb90ca0f6f154c45ed67e12a478dc4
parent43db88b8363d73ee2f5ffa094ff506414261bd11 (diff)
downloaddexon-solidity-43bda534102c95a85daddc64fb466eb8c88e2325.tar
dexon-solidity-43bda534102c95a85daddc64fb466eb8c88e2325.tar.gz
dexon-solidity-43bda534102c95a85daddc64fb466eb8c88e2325.tar.bz2
dexon-solidity-43bda534102c95a85daddc64fb466eb8c88e2325.tar.lz
dexon-solidity-43bda534102c95a85daddc64fb466eb8c88e2325.tar.xz
dexon-solidity-43bda534102c95a85daddc64fb466eb8c88e2325.tar.zst
dexon-solidity-43bda534102c95a85daddc64fb466eb8c88e2325.zip
Fixes issue where computing storage size for a number would take too long.
Fixes #4673.
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/ast/Types.cpp3
-rw-r--r--libsolidity/ast/Types.h3
-rw-r--r--test/libsolidity/syntaxTests/types/too_small_negative_numbers.sol4
4 files changed, 9 insertions, 2 deletions
diff --git a/Changelog.md b/Changelog.md
index b2f9bf05..5a7a2d1d 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -94,6 +94,7 @@ Bugfixes:
* Type Checker: Allow assignments to local variables of mapping types.
* Type Checker: Consider fixed size arrays when checking for recursive structs.
* Type Checker: Fix crashes in erroneous tuple assignments in which the type of the right hand side cannot be determined.
+ * Type Checker: Fix freeze for negative fixed-point literals very close to ``0``, such as ``-1e-100``.
* Type Checker: Report error when using structs in events without experimental ABIEncoderV2. This used to crash or log the wrong values.
* Type System: Allow arbitrary exponents for literals with a mantissa of zero.
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index 2dcfda42..21631693 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -1263,7 +1263,8 @@ shared_ptr<FixedPointType const> RationalNumberType::fixedPointType() const
return shared_ptr<FixedPointType const>();
// This means we round towards zero for positive and negative values.
bigint v = value.numerator() / value.denominator();
- if (negative)
+
+ if (negative && v != 0)
// modify value to satisfy bit requirements for negative numbers:
// add one bit for sign and decrement because negative numbers can be larger
v = (v - 1) << 1;
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index 3b57109d..787c9360 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -446,7 +446,8 @@ public:
/// @returns the smallest integer type that can hold the value or an empty pointer if not possible.
std::shared_ptr<IntegerType const> integerType() const;
- /// @returns the smallest fixed type that can hold the value or incurs the least precision loss.
+ /// @returns the smallest fixed type that can hold the value or incurs the least precision loss,
+ /// unless the value was truncated, then a suitable type will be chosen to indicate such event.
/// If the integer part does not fit, returns an empty pointer.
std::shared_ptr<FixedPointType const> fixedPointType() const;
diff --git a/test/libsolidity/syntaxTests/types/too_small_negative_numbers.sol b/test/libsolidity/syntaxTests/types/too_small_negative_numbers.sol
new file mode 100644
index 00000000..66bd9a8e
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/too_small_negative_numbers.sol
@@ -0,0 +1,4 @@
+contract C {
+ fixed8x80 a = -1e-100;
+}
+// ----