mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
Fixed division by zero due to thread race condition.
This commit is contained in:
parent
b8f998f76a
commit
638e9b4d7f
|
@ -1253,7 +1253,9 @@ namespace data
|
||||||
uint16_t inds[3];
|
uint16_t inds[3];
|
||||||
RAND_bytes ((uint8_t *)inds, sizeof (inds));
|
RAND_bytes ((uint8_t *)inds, sizeof (inds));
|
||||||
std::unique_lock<std::mutex> l(m_RouterInfosMutex);
|
std::unique_lock<std::mutex> l(m_RouterInfosMutex);
|
||||||
inds[0] %= m_RouterInfos.size ();
|
auto count = m_RouterInfos.size ();
|
||||||
|
if(count == 0) return nullptr;
|
||||||
|
inds[0] %= count;
|
||||||
auto it = m_RouterInfos.begin ();
|
auto it = m_RouterInfos.begin ();
|
||||||
std::advance (it, inds[0]);
|
std::advance (it, inds[0]);
|
||||||
// try random router
|
// try random router
|
||||||
|
|
|
@ -861,7 +861,9 @@ namespace transport
|
||||||
uint16_t inds[3];
|
uint16_t inds[3];
|
||||||
RAND_bytes ((uint8_t *)inds, sizeof (inds));
|
RAND_bytes ((uint8_t *)inds, sizeof (inds));
|
||||||
std::unique_lock<std::mutex> l(m_PeersMutex);
|
std::unique_lock<std::mutex> l(m_PeersMutex);
|
||||||
inds[0] %= m_Peers.size ();
|
auto count = m_Peers.size ();
|
||||||
|
if(count == 0) return nullptr;
|
||||||
|
inds[0] %= count;
|
||||||
auto it = m_Peers.begin ();
|
auto it = m_Peers.begin ();
|
||||||
std::advance (it, inds[0]);
|
std::advance (it, inds[0]);
|
||||||
// try random peer
|
// try random peer
|
||||||
|
|
Loading…
Reference in a new issue