diff options
author | Christian Parpart <christian@parpart.family> | 2018-07-31 22:18:00 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2018-08-01 19:02:59 +0800 |
commit | 38f9667e090492d0581a5f1a14a48504242ca28e (patch) | |
tree | 27c2b3a9e4c77512331054a53c863a94efa3b58e /libdevcore | |
parent | ef269bf40d3c6fc044c27654473353c556402b77 (diff) | |
download | dexon-solidity-38f9667e090492d0581a5f1a14a48504242ca28e.tar dexon-solidity-38f9667e090492d0581a5f1a14a48504242ca28e.tar.gz dexon-solidity-38f9667e090492d0581a5f1a14a48504242ca28e.tar.bz2 dexon-solidity-38f9667e090492d0581a5f1a14a48504242ca28e.tar.lz dexon-solidity-38f9667e090492d0581a5f1a14a48504242ca28e.tar.xz dexon-solidity-38f9667e090492d0581a5f1a14a48504242ca28e.tar.zst dexon-solidity-38f9667e090492d0581a5f1a14a48504242ca28e.zip |
Guard CycleDetector against recursion exhaustion.
fixes #3935.
Diffstat (limited to 'libdevcore')
-rw-r--r-- | libdevcore/Algorithms.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/libdevcore/Algorithms.h b/libdevcore/Algorithms.h index b2540668..7fe2472d 100644 --- a/libdevcore/Algorithms.h +++ b/libdevcore/Algorithms.h @@ -32,11 +32,13 @@ template <typename V> class CycleDetector { public: + using Visitor = std::function<void(V const&, CycleDetector&, size_t)>; + /// Initializes the cycle detector /// @param _visit function that is given the current vertex /// and is supposed to call @a run on all /// adjacent vertices. - explicit CycleDetector(std::function<void(V const&, CycleDetector&)> _visit): + explicit CycleDetector(Visitor _visit): m_visit(std::move(_visit)) { } @@ -55,7 +57,7 @@ public: m_processing.insert(&_vertex); m_depth++; - m_visit(_vertex, *this); + m_visit(_vertex, *this, m_depth); m_depth--; if (m_firstCycleVertex && m_depth == 1) m_firstCycleVertex = &_vertex; @@ -66,7 +68,7 @@ public: } private: - std::function<void(V const&, CycleDetector&)> m_visit; + Visitor m_visit; std::set<V const*> m_processing; std::set<V const*> m_processed; size_t m_depth = 0; |