Skip to content
Permalink
Browse files

Check validity of iterator before dereferencing

  • Loading branch information...
bdr99 committed Aug 14, 2019
1 parent fdfa14d commit 8857db98339bbf902cbc95c24822dbe1ce5ffa05
Showing with 7 additions and 4 deletions.
  1. +7 −4 Source/Core/Core/NetPlayClient.cpp
@@ -316,12 +316,15 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
PlayerId pid;
packet >> pid;

INFO_LOG(NETPLAY, "Player %s (%d) left", m_players.find(pid)->second.name.c_str(), pid);

m_dialog->OnPlayerDisconnect(m_players.find(pid)->second.name);

{
std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
const auto it = m_players.find(pid);
if (it == m_players.end())
break;

const auto& player = it->second;
INFO_LOG(NETPLAY, "Player %s (%d) left", player.name.c_str(), pid);
m_dialog->OnPlayerDisconnect(player.name);
m_players.erase(m_players.find(pid));
}

0 comments on commit 8857db9

Please sign in to comment.
You can’t perform that action at this time.