From ced6d20295a8263757d57c02a07ffcb66688a163 Mon Sep 17 00:00:00 2001 From: Craig Robbins Date: Fri, 6 Mar 2015 20:21:51 +1000 Subject: For usages of assert() that are meant to persist in Release builds (when NDEBUG is defined), replace those usages with persistent alternatives --- src/network/connection.cpp | 74 ++++++++++++++++------------------- src/network/connection.h | 6 +-- src/network/packethandlers/client.cpp | 8 ++-- 3 files changed, 41 insertions(+), 47 deletions(-) (limited to 'src/network') diff --git a/src/network/connection.cpp b/src/network/connection.cpp index b73981ccc..fb31a07f0 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -312,16 +312,16 @@ BufferedPacket ReliablePacketBuffer::popSeqnum(u16 seqnum) void ReliablePacketBuffer::insert(BufferedPacket &p,u16 next_expected) { JMutexAutoLock listlock(m_list_mutex); - assert(p.data.getSize() >= BASE_HEADER_SIZE+3); + FATAL_ERROR_IF(p.data.getSize() < BASE_HEADER_SIZE+3, "Invalid data size"); u8 type = readU8(&p.data[BASE_HEADER_SIZE+0]); - assert(type == TYPE_RELIABLE); + sanity_check(type == TYPE_RELIABLE); u16 seqnum = readU16(&p.data[BASE_HEADER_SIZE+1]); - assert(seqnum_in_window(seqnum,next_expected,MAX_RELIABLE_WINDOW_SIZE)); - assert(seqnum != next_expected); + sanity_check(seqnum_in_window(seqnum, next_expected, MAX_RELIABLE_WINDOW_SIZE)); + sanity_check(seqnum != next_expected); ++m_list_size; - assert(m_list_size <= SEQNUM_MAX+1); + sanity_check(m_list_size <= SEQNUM_MAX+1); // FIXME: Handle the error? // Find the right place for the packet and insert it there // If list is empty, just add it @@ -377,9 +377,9 @@ void ReliablePacketBuffer::insert(BufferedPacket &p,u16 next_expected) throw IncomingDataCorruption("duplicated packet isn't same as original one"); } - assert(readU16(&(i->data[BASE_HEADER_SIZE+1])) == seqnum); - assert(i->data.getSize() == p.data.getSize()); - assert(i->address == p.address); + sanity_check(readU16(&(i->data[BASE_HEADER_SIZE+1])) == seqnum); + sanity_check(i->data.getSize() == p.data.getSize()); + sanity_check(i->address == p.address); /* nothing to do this seems to be a resent packet */ /* for paranoia reason data should be compared */ @@ -449,9 +449,9 @@ SharedBuffer IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable) { JMutexAutoLock listlock(m_map_mutex); u32 headersize = BASE_HEADER_SIZE + 7; - assert(p.data.getSize() >= headersize); + FATAL_ERROR_IF(p.data.getSize() < headersize, "Invalid data size"); u8 type = readU8(&p.data[BASE_HEADER_SIZE+0]); - assert(type == TYPE_SPLIT); + sanity_check(type == TYPE_SPLIT); u16 seqnum = readU16(&p.data[BASE_HEADER_SIZE+1]); u16 chunk_count = readU16(&p.data[BASE_HEADER_SIZE+3]); u16 chunk_num = readU16(&p.data[BASE_HEADER_SIZE+5]); @@ -898,7 +898,7 @@ void Peer::DecUseCount() { { JMutexAutoLock lock(m_exclusive_access_mutex); - assert(m_usage > 0); + sanity_check(m_usage > 0); m_usage--; if (!((m_pending_deletion) && (m_usage == 0))) @@ -1085,7 +1085,7 @@ bool UDPPeer::processReliableSendCommand( - BASE_HEADER_SIZE - RELIABLE_HEADER_SIZE; - assert(c.data.getSize() < MAX_RELIABLE_WINDOW_SIZE*512); + sanity_check(c.data.getSize() < MAX_RELIABLE_WINDOW_SIZE*512); std::list > originals; u16 split_sequence_number = channels[c.channelnum].readNextSplitSeqNum(); @@ -1142,7 +1142,7 @@ bool UDPPeer::processReliableSendCommand( channels[c.channelnum].queued_reliables.push(p); pcount++; } - assert(channels[c.channelnum].queued_reliables.size() < 0xFFFF); + sanity_check(channels[c.channelnum].queued_reliables.size() < 0xFFFF); return true; } else { @@ -1160,7 +1160,7 @@ bool UDPPeer::processReliableSendCommand( = channels[c.channelnum].putBackSequenceNumber( (initial_sequence_number+toadd.size() % (SEQNUM_MAX+1))); - assert(successfully_put_back_sequence_number); + FATAL_ERROR_IF(!successfully_put_back_sequence_number, "error"); } LOG(dout_con<getDesc() << " Windowsize exceeded on reliable sending " @@ -1212,13 +1212,13 @@ void UDPPeer::RunCommandQueues( u16 UDPPeer::getNextSplitSequenceNumber(u8 channel) { - assert(channel < CHANNEL_COUNT); + assert(channel < CHANNEL_COUNT); // Pre-condition return channels[channel].readNextIncomingSeqNum(); } void UDPPeer::setNextSplitSequenceNumber(u8 channel, u16 seqnum) { - assert(channel < CHANNEL_COUNT); + assert(channel < CHANNEL_COUNT); // Pre-condition channels[channel].setNextSplitSeqNum(seqnum); } @@ -1226,7 +1226,7 @@ SharedBuffer UDPPeer::addSpiltPacket(u8 channel, BufferedPacket toadd, bool reliable) { - assert(channel < CHANNEL_COUNT); + assert(channel < CHANNEL_COUNT); // Pre-condition return channels[channel].incoming_splits.insert(toadd,reliable); } @@ -1496,7 +1496,6 @@ void ConnectionSendThread::sendAsPacketReliable(BufferedPacket& p, Channel* chan LOG(derr_con<getDesc() <<"WARNING: Going to send a reliable packet" <<" in outgoing buffer" <getDesc() <<" INFO: dropped packet for non existent peer_id: " << peer_id << std::endl); - assert(reliable && "trying to send raw packet reliable but no peer found!"); + FATAL_ERROR_IF(!reliable, "Trying to send raw packet reliable but no peer found!"); return false; } Channel *channel = &(dynamic_cast(&peer)->channels[channelnum]); @@ -1582,7 +1581,7 @@ bool ConnectionSendThread::rawSendAsPacket(u16 peer_id, u8 channelnum, void ConnectionSendThread::processReliableCommand(ConnectionCommand &c) { - assert(c.reliable); + assert(c.reliable); // Pre-condition switch(c.type) { case CONNCMD_NONE: @@ -1626,7 +1625,7 @@ void ConnectionSendThread::processReliableCommand(ConnectionCommand &c) case CONNCMD_CONNECT: case CONNCMD_DISCONNECT: case CONCMD_ACK: - assert("Got command that shouldn't be reliable as reliable command" == 0); + FATAL_ERROR("Got command that shouldn't be reliable as reliable command"); default: LOG(dout_con<getDesc() <<" Invalid reliable command type: " << c.type <getDesc() <<" Invalid command type: " << c.type < data) { - assert(channelnum < CHANNEL_COUNT); + assert(channelnum < CHANNEL_COUNT); // Pre-condition PeerHelper peer = m_connection->getPeerNoEx(peer_id); if (!peer) @@ -2331,7 +2330,7 @@ SharedBuffer ConnectionReceiveThread::processPacket(Channel *channel, if (MAX_UDP_PEERS <= 65535 && peer_id >= MAX_UDP_PEERS) { errorstream << "Something is wrong with peer_id" << std::endl; - assert(0); + FATAL_ERROR(""); } if (type == TYPE_CONTROL) @@ -2343,7 +2342,7 @@ SharedBuffer ConnectionReceiveThread::processPacket(Channel *channel, if (controltype == CONTROLTYPE_ACK) { - assert(channel != 0); + FATAL_ERROR_IF(channel == 0, "Invalid channel (0)"); if (packetdata.getSize() < 4) throw InvalidIncomingDataException ("packetdata.getSize() < 4 (ACK header size)"); @@ -2511,7 +2510,7 @@ SharedBuffer ConnectionReceiveThread::processPacket(Channel *channel, } else if (type == TYPE_RELIABLE) { - assert(channel != 0); + FATAL_ERROR_IF(channel == 0, "Invalid channel (0)"); // Recursive reliable packets not allowed if (reliable) throw InvalidIncomingDataException("Found nested reliable packets"); @@ -2635,10 +2634,7 @@ SharedBuffer ConnectionReceiveThread::processPacket(Channel *channel, } // We should never get here. - // If you get here, add an exception or a return to some of the - // above conditionals. - assert(0); - throw BaseException("Error in Channel::ProcessPacket()"); + FATAL_ERROR("Invalid execution point"); } /* @@ -2724,7 +2720,7 @@ Connection::~Connection() /* Internal stuff */ void Connection::putEvent(ConnectionEvent &e) { - assert(e.type != CONNEVENT_NONE); + assert(e.type != CONNEVENT_NONE); // Pre-condition m_event_queue.push_back(e); } @@ -2738,7 +2734,7 @@ PeerHelper Connection::getPeer(u16 peer_id) } // Error checking - assert(node->second->id == peer_id); + FATAL_ERROR_IF(node->second->id != peer_id, "Invalid peer id"); return PeerHelper(node->second); } @@ -2753,7 +2749,7 @@ PeerHelper Connection::getPeerNoEx(u16 peer_id) } // Error checking - assert(node->second->id == peer_id); + FATAL_ERROR_IF(node->second->id != peer_id, "Invalid peer id"); return PeerHelper(node->second); } @@ -2925,7 +2921,7 @@ u32 Connection::Receive(u16 &peer_id, SharedBuffer &data) void Connection::Send(u16 peer_id, u8 channelnum, NetworkPacket* pkt, bool reliable) { - assert(channelnum < CHANNEL_COUNT); + assert(channelnum < CHANNEL_COUNT); // Pre-condition ConnectionCommand c; @@ -2955,9 +2951,7 @@ float Connection::getLocalStat(rate_stat_type type) { PeerHelper peer = getPeerNoEx(PEER_ID_SERVER); - if (!peer) { - assert("Connection::getLocalStat we couldn't get our own peer? are you serious???" == 0); - } + FATAL_ERROR_IF(!peer, "Connection::getLocalStat we couldn't get our own peer? are you serious???"); float retval = 0.0; @@ -2982,7 +2976,7 @@ float Connection::getLocalStat(rate_stat_type type) retval += dynamic_cast(&peer)->channels[j].getCurrentLossRateKB(); break; default: - assert("Connection::getLocalStat Invalid stat type" == 0); + FATAL_ERROR("Connection::getLocalStat Invalid stat type"); } } return retval; @@ -3075,7 +3069,7 @@ void Connection::DisconnectPeer(u16 peer_id) void Connection::sendAck(u16 peer_id, u8 channelnum, u16 seqnum) { - assert(channelnum < CHANNEL_COUNT); + assert(channelnum < CHANNEL_COUNT); // Pre-condition LOG(dout_con<getString(0), pkt->getSize()); @@ -602,7 +602,7 @@ void Client::handleCommand_ItemDef(NetworkPacket* pkt) // Mesh update thread must be stopped while // updating content definitions - assert(!m_mesh_update_thread.IsRunning()); + sanity_check(!m_mesh_update_thread.IsRunning()); // Decompress item definitions std::string datastring(pkt->getString(0), pkt->getSize()); -- cgit v1.2.3