From a3ae20fc15cedbd9fc2bf06e44484bceeb2e60f7 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 29 May 2014 20:09:10 -0400 Subject: [PATCH 1/2] Remove the use of a delete[] in NetPlayServer. We just use a vector instead of a raw pointer. --- Source/Core/Core/NetPlayServer.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index c7145079bf..a84373c271 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include + #include "Core/NetPlayServer.h" NetPlayServer::~NetPlayServer() @@ -424,15 +426,14 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, sf::SocketTCP& socket) PadMapping map = 0; u8 size; packet >> map >> size; - u8* data = new u8[size]; - for (unsigned int i = 0; i < size; ++i) + std::vector data(size); + for (size_t i = 0; i < data.size(); ++i) packet >> data[i]; // If the data is not from the correct player, // then disconnect them. if (m_wiimote_map[map] != player.pid) { - delete[] data; return 1; } @@ -441,10 +442,8 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, sf::SocketTCP& socket) spac << (MessageId)NP_MSG_WIIMOTE_DATA; spac << map; spac << size; - for (unsigned int i = 0; i < size; ++i) - spac << data[i]; - - delete[] data; + for (const u8& byte : data) + spac << byte; std::lock_guard lks(m_crit.send); SendToClients(spac, player.pid); From 7babc635cb7d2f9d1c40f016ee2623b81cc8e4d2 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 29 May 2014 20:30:03 -0400 Subject: [PATCH 2/2] Compress a for loop in NetPlayServer. Also gets rid of a redundant return from a void function. --- Source/Core/Core/NetPlayServer.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index a84373c271..85041efb24 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -114,15 +114,8 @@ void NetPlayServer::ThreadFunc() } // close listening socket and client sockets - { - std::map::reverse_iterator - i = m_players.rbegin(), - e = m_players.rend(); - for ( ; i!=e; ++i) - i->second.socket.Close(); - } - - return; + for (auto& player_entry : m_players) + player_entry.second.socket.Close(); } // called from ---NETPLAY--- thread