From: Arnaud Giersch Date: Sun, 20 Aug 2017 15:52:31 +0000 (+0200) Subject: Handle case when active_peers is empty. X-Git-Tag: v3_17~152^2~25 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/82bc0605a155764eb531f71670b028fcf1717412 Handle case when active_peers is empty. --- diff --git a/examples/s4u/app-bittorrent/s4u_peer.cpp b/examples/s4u/app-bittorrent/s4u_peer.cpp index 0b03bdbac8..a9c38f868f 100644 --- a/examples/s4u/app-bittorrent/s4u_peer.cpp +++ b/examples/s4u/app-bittorrent/s4u_peer.cpp @@ -546,8 +546,13 @@ void Peer::updateChokedPeers() round_ = (round_ + 1) % 3; Connection* chosen_peer = nullptr; // select first active peer and remove it from the set - Connection* choked_peer = *(active_peers.begin()); - active_peers.erase(choked_peer); + Connection* choked_peer; + if (active_peers.empty()) { + choked_peer = nullptr; + } else { + choked_peer = *active_peers.begin(); + active_peers.erase(choked_peer); + } /**If we are currently seeding, we unchoke the peer which has been unchoked the last time.*/ if (hasFinished()) {