From d75f8595dece344be508eecd66417c2344a8ed08 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 7 Aug 2015 14:31:27 +0200 Subject: [PATCH] Copy map before looping over it because it might be modified. --- libdevcore/CommonData.h | 18 ++++++++++++++++++ libethcore/Common.h | 12 ++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h index 0faba8e8e..0556dc086 100644 --- a/libdevcore/CommonData.h +++ b/libdevcore/CommonData.h @@ -349,6 +349,24 @@ std::vector keysOf(std::unordered_map const& _m) return ret; } +template +std::vector valuesOf(std::map const& _m) +{ + std::vector ret(_m.size()); + for (auto const& i: _m) + ret.push_back(i.second); + return ret; +} + +template +std::vector valuesOf(std::unordered_map const& _m) +{ + std::vector ret(_m.size()); + for (auto const& i: _m) + ret.push_back(i.second); + return ret; +} + template bool contains(T const& _t, V const& _v) { diff --git a/libethcore/Common.h b/libethcore/Common.h index 883a14e9b..621a893f1 100644 --- a/libethcore/Common.h +++ b/libethcore/Common.h @@ -154,9 +154,9 @@ public: friend class Signal; public: - ~HandlerAux() { if (m_s) m_s->m_fire.erase(m_i); m_s = nullptr; } + ~HandlerAux() { if (m_s) m_s->m_fire.erase(m_i); } void reset() { m_s = nullptr; } - void fire(Args&&... _args) { m_h(std::forward(_args)...); } + void fire(Args const&... _args) { m_h(_args...); } private: HandlerAux(unsigned _i, Signal* _s, Callback const& _h): m_i(_i), m_s(_s), m_h(_h) {} @@ -181,11 +181,11 @@ public: return h; } - void operator()(Args&... _args) + void operator()(Args const&... _args) { - for (auto const& f: m_fire) - if (auto h = f.second.lock()) - h->fire(std::forward(_args)...); + for (auto const& f: valuesOf(m_fire)) + if (auto h = f.lock()) + h->fire(_args...); } private: