From 0603b3dafd6908e98f142d0a9a7fd026ec146122 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Tue, 8 Dec 2009 00:46:38 +0100 Subject: [PATCH] sanity checks; server crash fix --- cockatrice/src/cardzone.cpp | 4 ++++ cockatrice/src/player.cpp | 4 ++++ common/server.cpp | 3 +-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cockatrice/src/cardzone.cpp b/cockatrice/src/cardzone.cpp index de5af722..86a554e9 100644 --- a/cockatrice/src/cardzone.cpp +++ b/cockatrice/src/cardzone.cpp @@ -99,6 +99,10 @@ void CardZone::addCard(CardItem *card, bool reorganize, int x, int y) CardItem *CardZone::getCard(int cardId, const QString &cardName) { CardItem *c = cards.findCard(cardId, false); + if (!c) { + qDebug() << "CardZone::getCard: card id=" << cardId << "not found"; + return 0; + } // If the card's id is -1, this zone is invisible, // so we need to give the card an id and a name as it comes out. // It can be assumed that in an invisible zone, all cards are equal. diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 7d7a6f09..a7638994 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -563,6 +563,10 @@ void Player::eventSetCardAttr(Event_SetCardAttr *event) emit logSetTapped(this, QString("-1"), event->getAttrValue() == "1"); } else { CardItem *card = zone->getCard(event->getCardId(), QString()); + if (!card) { + qDebug() << "Player::eventSetCardAttr: card id=" << event->getCardId() << "not found"; + return; + } setCardAttrHelper(card, event->getAttrName(), event->getAttrValue(), false); } } diff --git a/common/server.cpp b/common/server.cpp index 534fa119..7026de83 100644 --- a/common/server.cpp +++ b/common/server.cpp @@ -65,8 +65,7 @@ void Server::closeOldSession(const QString &playerName) } if (session) { qDebug() << "found"; - removeClient(session); - delete session; + delete session; // ~Server_ProtocolHandler() will call Server::removeClient } }