From 38f9667e090492d0581a5f1a14a48504242ca28e Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Tue, 31 Jul 2018 16:18:00 +0200 Subject: Guard CycleDetector against recursion exhaustion. fixes #3935. --- libdevcore/Algorithms.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'libdevcore') 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 class CycleDetector { public: + using Visitor = std::function; + /// 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 _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 m_visit; + Visitor m_visit; std::set m_processing; std::set m_processed; size_t m_depth = 0; -- cgit