Fix bug found by coverity scan. Hopefully I didn't break anything

This commit is contained in:
Marianne Gagnon
2014-02-01 18:36:29 -05:00
parent aa324f31e6
commit b726ff79b1
5 changed files with 10 additions and 6 deletions

View File

@@ -123,7 +123,7 @@ void NetworkManager::notifyEvent(Event* event)
((addr>>24)&0xff),
((addr>>16)&0xff),
((addr>>8)&0xff),
(addr&0xff), event->data().c_str());
(addr & 0xff), event->data().std_string().c_str());
}

View File

@@ -146,16 +146,20 @@ class NetworkString
return *this;
}
const char* c_str() const
const std::string std_string() const
{
std::string str(m_string.begin(), m_string.end());
return str.c_str();
return str;
}
int size() const
{
return m_string.size();
}
uint8_t* getBytes() { return &m_string[0]; };
const uint8_t* getBytes() const { return &m_string[0]; };
template<typename T, size_t n>
T get(int pos) const
{

View File

@@ -144,7 +144,7 @@ void ProtocolManager::notifyEvent(Event* event)
pthread_mutex_unlock(&m_protocols_mutex);
if (searchedProtocol == PROTOCOL_NONE) // no protocol was aimed, show the msg to debug
{
Log::debug("ProtocolManager", "NO PROTOCOL : Message is \"%s\"", event2->data().c_str());
Log::debug("ProtocolManager", "NO PROTOCOL : Message is \"%s\"", event2->data().std_string().c_str());
}
if (protocols_ids.size() != 0)

View File

@@ -302,7 +302,7 @@ uint8_t* STKHost::receiveRawPacket(TransportAddress sender, int max_tries)
void STKHost::broadcastPacket(const NetworkString& data, bool reliable)
{
ENetPacket* packet = enet_packet_create(data.c_str(), data.size()+1,
ENetPacket* packet = enet_packet_create(data.getBytes(), data.size() + 1,
(reliable ? ENET_PACKET_FLAG_RELIABLE : ENET_PACKET_FLAG_UNSEQUENCED));
enet_host_broadcast(m_host, 0, packet);
STKHost::logPacket(data, false);

View File

@@ -95,7 +95,7 @@ void STKPeer::sendPacket(NetworkString const& data, bool reliable)
data.size(), (m_peer->address.host>>0)&0xff,
(m_peer->address.host>>8)&0xff,(m_peer->address.host>>16)&0xff,
(m_peer->address.host>>24)&0xff,m_peer->address.port);
ENetPacket* packet = enet_packet_create(data.c_str(), data.size()+1,
ENetPacket* packet = enet_packet_create(data.getBytes(), data.size() + 1,
(reliable ? ENET_PACKET_FLAG_RELIABLE : ENET_PACKET_FLAG_UNSEQUENCED));
/* to debug the packet output
printf("STKPeer: ");