mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
Fix #227: Transports::GetRandomPeer() crashes if m_Peers is empty
This commit is contained in:
parent
28969bfeab
commit
d0b2a0da14
@ -491,10 +491,14 @@ namespace transport
|
||||
|
||||
std::shared_ptr<const i2p::data::RouterInfo> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user