diff --git a/Transports.cpp b/Transports.cpp index 5f2d2764..52856c5f 100644 --- a/Transports.cpp +++ b/Transports.cpp @@ -491,10 +491,14 @@ namespace transport std::shared_ptr Transports::GetRandomPeer () const { - CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator (); - auto it = m_Peers.begin (); - std::advance (it, rnd.GenerateWord32 (0, m_Peers.size () - 1)); - return it != m_Peers.end () ? it->second.router : nullptr; + if(m_Peers.empty()) // ensure m.Peers.size() >= 1 + return nullptr; + + CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator(); + auto it = m_Peers.begin(); + std::advance(it, rnd.GenerateWord32(0, m_Peers.size () - 1)); + + return it->second.router; } } }