diff options
author | Balajiganapathi S <balajiganapathi.s@gmail.com> | 2017-11-18 00:55:07 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-11-22 10:07:56 +0800 |
commit | d102deaec90f6f5bfe38140b459a05215d3254f9 (patch) | |
tree | a6f8f5df73bbe5454fe472d4d80042d5a071d8d3 /libsolidity/analysis | |
parent | c0b49694518d333a8ad62623321f839fc3b4bc6a (diff) | |
download | dexon-solidity-d102deaec90f6f5bfe38140b459a05215d3254f9.tar dexon-solidity-d102deaec90f6f5bfe38140b459a05215d3254f9.tar.gz dexon-solidity-d102deaec90f6f5bfe38140b459a05215d3254f9.tar.bz2 dexon-solidity-d102deaec90f6f5bfe38140b459a05215d3254f9.tar.lz dexon-solidity-d102deaec90f6f5bfe38140b459a05215d3254f9.tar.xz dexon-solidity-d102deaec90f6f5bfe38140b459a05215d3254f9.tar.zst dexon-solidity-d102deaec90f6f5bfe38140b459a05215d3254f9.zip |
Detect cyclic constant definitions
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r-- | libsolidity/analysis/ConstantEvaluator.cpp | 16 | ||||
-rw-r--r-- | libsolidity/analysis/ConstantEvaluator.h | 7 |
2 files changed, 15 insertions, 8 deletions
diff --git a/libsolidity/analysis/ConstantEvaluator.cpp b/libsolidity/analysis/ConstantEvaluator.cpp index 50044eb6..cb8bbc05 100644 --- a/libsolidity/analysis/ConstantEvaluator.cpp +++ b/libsolidity/analysis/ConstantEvaluator.cpp @@ -77,18 +77,22 @@ void ConstantEvaluator::endVisit(Literal const& _literal) void ConstantEvaluator::endVisit(Identifier const& _identifier) { - VariableDeclaration const *variableDeclaration = dynamic_cast<VariableDeclaration const *>(_identifier.annotation().referencedDeclaration); + VariableDeclaration const* variableDeclaration = dynamic_cast<VariableDeclaration const*>(_identifier.annotation().referencedDeclaration); if (!variableDeclaration) return; if (!variableDeclaration->isConstant()) m_errorReporter.fatalTypeError(_identifier.location(), "Identifier must be declared constant."); ASTPointer<Expression> value = variableDeclaration->value(); - if (value) - { - if (!value->annotation().type) - ConstantEvaluator e(*value, m_errorReporter); + if (!value) + m_errorReporter.fatalTypeError(_identifier.location(), "Constant identifier declaration must have a constant value."); - _identifier.annotation().type = value->annotation().type; + if (!value->annotation().type) + { + if (m_depth > 32) + m_errorReporter.fatalTypeError(_identifier.location(), "Cyclic constant definition."); + ConstantEvaluator e(*value, m_errorReporter, m_depth + 1); } + + _identifier.annotation().type = value->annotation().type; } diff --git a/libsolidity/analysis/ConstantEvaluator.h b/libsolidity/analysis/ConstantEvaluator.h index 42ccfe7e..6725d610 100644 --- a/libsolidity/analysis/ConstantEvaluator.h +++ b/libsolidity/analysis/ConstantEvaluator.h @@ -38,8 +38,9 @@ class TypeChecker; class ConstantEvaluator: private ASTConstVisitor { public: - ConstantEvaluator(Expression const& _expr, ErrorReporter& _errorReporter): - m_errorReporter(_errorReporter) + ConstantEvaluator(Expression const& _expr, ErrorReporter& _errorReporter, size_t _newDepth = 0): + m_errorReporter(_errorReporter), + m_depth(_newDepth) { _expr.accept(*this); } @@ -51,6 +52,8 @@ private: virtual void endVisit(Identifier const& _identifier); ErrorReporter& m_errorReporter; + /// Current recursion depth. + size_t m_depth; }; } |