Remove the use of a delete[] in NetPlayServer.

We just use a vector instead of a raw pointer.
This commit is contained in:
Lioncash 2014-05-29 20:09:10 -04:00
parent 3097345929
commit a3ae20fc15
1 changed files with 6 additions and 7 deletions

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2 // Licensed under GPLv2
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <vector>
#include "Core/NetPlayServer.h" #include "Core/NetPlayServer.h"
NetPlayServer::~NetPlayServer() NetPlayServer::~NetPlayServer()
@ -424,15 +426,14 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, sf::SocketTCP& socket)
PadMapping map = 0; PadMapping map = 0;
u8 size; u8 size;
packet >> map >> size; packet >> map >> size;
u8* data = new u8[size]; std::vector<u8> data(size);
for (unsigned int i = 0; i < size; ++i) for (size_t i = 0; i < data.size(); ++i)
packet >> data[i]; packet >> data[i];
// If the data is not from the correct player, // If the data is not from the correct player,
// then disconnect them. // then disconnect them.
if (m_wiimote_map[map] != player.pid) if (m_wiimote_map[map] != player.pid)
{ {
delete[] data;
return 1; return 1;
} }
@ -441,10 +442,8 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, sf::SocketTCP& socket)
spac << (MessageId)NP_MSG_WIIMOTE_DATA; spac << (MessageId)NP_MSG_WIIMOTE_DATA;
spac << map; spac << map;
spac << size; spac << size;
for (unsigned int i = 0; i < size; ++i) for (const u8& byte : data)
spac << data[i]; spac << byte;
delete[] data;
std::lock_guard<std::recursive_mutex> lks(m_crit.send); std::lock_guard<std::recursive_mutex> lks(m_crit.send);
SendToClients(spac, player.pid); SendToClients(spac, player.pid);