From e127cb74b6d3611a70cb642efc72e1ef0202be17 Mon Sep 17 00:00:00 2001 From: ctrlaltca Date: Sat, 27 Jan 2018 19:31:44 +0100 Subject: [PATCH] Fixed most issues from codacy (#3050) --- cockatrice/src/cardlist.cpp | 2 +- cockatrice/src/filtertree.cpp | 4 ++-- cockatrice/src/filtertreemodel.cpp | 3 +-- cockatrice/src/lineeditcompleter.cpp | 2 +- cockatrice/src/messagelogwidget.cpp | 3 ++- cockatrice/src/pictureloader.h | 1 - cockatrice/src/update_downloader.cpp | 2 +- common/server.cpp | 2 +- common/server_player.cpp | 12 +++++------- servatrice/src/main.cpp | 13 ++++--------- servatrice/src/servatrice.cpp | 6 ++++-- servatrice/src/servatrice_connection_pool.cpp | 2 +- servatrice/src/servatrice_database_interface.cpp | 2 +- servatrice/src/serversocketinterface.cpp | 2 +- servatrice/src/settingscache.h | 1 - servatrice/src/signalhandler.cpp | 2 +- 16 files changed, 26 insertions(+), 33 deletions(-) diff --git a/cockatrice/src/cardlist.cpp b/cockatrice/src/cardlist.cpp index 11c2a262..7324f8a0 100644 --- a/cockatrice/src/cardlist.cpp +++ b/cockatrice/src/cardlist.cpp @@ -37,7 +37,7 @@ private: int flags; public: - compareFunctor(int _flags) : flags(_flags) + explicit compareFunctor(int _flags) : flags(_flags) { } inline bool operator()(CardItem *a, CardItem *b) const diff --git a/cockatrice/src/filtertree.cpp b/cockatrice/src/filtertree.cpp index 0149d7d9..ea4d4af5 100644 --- a/cockatrice/src/filtertree.cpp +++ b/cockatrice/src/filtertree.cpp @@ -35,7 +35,7 @@ const FilterItemList *LogicMap::findTypeList(CardFilter::Type type) const { QList::const_iterator i; - for (i = childNodes.constBegin(); i != childNodes.constEnd(); i++) { + for (i = childNodes.constBegin(); i != childNodes.constEnd(); ++i) { if ((*i)->type == type) { return *i; } @@ -49,7 +49,7 @@ FilterItemList *LogicMap::typeList(CardFilter::Type type) QList::iterator i; int count = 0; - for (i = childNodes.begin(); i != childNodes.end(); i++) { + for (i = childNodes.begin(); i != childNodes.end(); ++i) { if ((*i)->type == type) { break; } diff --git a/cockatrice/src/filtertreemodel.cpp b/cockatrice/src/filtertreemodel.cpp index f37ea38e..29bf6b58 100644 --- a/cockatrice/src/filtertreemodel.cpp +++ b/cockatrice/src/filtertreemodel.cpp @@ -220,7 +220,6 @@ QModelIndex FilterTreeModel::parent(const QModelIndex &ind) const { const FilterTreeNode *node; FilterTreeNode *parent; - int row; QModelIndex idx; if (!ind.isValid()) @@ -232,7 +231,7 @@ QModelIndex FilterTreeModel::parent(const QModelIndex &ind) const parent = node->parent(); if (parent) { - row = parent->index(); + int row = parent->index(); if (row < 0) return QModelIndex(); idx = createIndex(row, 0, parent); diff --git a/cockatrice/src/lineeditcompleter.cpp b/cockatrice/src/lineeditcompleter.cpp index b84e9d14..e3eec7e7 100644 --- a/cockatrice/src/lineeditcompleter.cpp +++ b/cockatrice/src/lineeditcompleter.cpp @@ -9,7 +9,7 @@ #include #include -LineEditCompleter::LineEditCompleter(QWidget *parent) : QLineEdit(parent) +LineEditCompleter::LineEditCompleter(QWidget *parent) : QLineEdit(parent), c(nullptr) { } diff --git a/cockatrice/src/messagelogwidget.cpp b/cockatrice/src/messagelogwidget.cpp index 06b0500d..100ff4db 100644 --- a/cockatrice/src/messagelogwidget.cpp +++ b/cockatrice/src/messagelogwidget.cpp @@ -796,6 +796,7 @@ MessageLogWidget::MessageLogWidget(const TabSupervisor *_tabSupervisor, const UserlistProxy *_userlistProxy, TabGame *_game, QWidget *parent) - : ChatView(_tabSupervisor, _userlistProxy, _game, true, parent), currentContext(MessageContext_None) + : ChatView(_tabSupervisor, _userlistProxy, _game, true, parent), mulliganNumber(0), + currentContext(MessageContext_None) { } diff --git a/cockatrice/src/pictureloader.h b/cockatrice/src/pictureloader.h index f71d6986..6878e5f9 100644 --- a/cockatrice/src/pictureloader.h +++ b/cockatrice/src/pictureloader.h @@ -20,7 +20,6 @@ private: CardInfo *card; QList sortedSets; int setIndex; - bool hq; public: PictureToLoad(CardInfo *_card = 0); diff --git a/cockatrice/src/update_downloader.cpp b/cockatrice/src/update_downloader.cpp index fd9aeead..2f7b57ba 100644 --- a/cockatrice/src/update_downloader.cpp +++ b/cockatrice/src/update_downloader.cpp @@ -3,7 +3,7 @@ #include "update_downloader.h" -UpdateDownloader::UpdateDownloader(QObject *parent) : QObject(parent) +UpdateDownloader::UpdateDownloader(QObject *parent) : QObject(parent), response(nullptr) { netMan = new QNetworkAccessManager(this); } diff --git a/common/server.cpp b/common/server.cpp index 526d98b7..92618949 100644 --- a/common/server.cpp +++ b/common/server.cpp @@ -426,7 +426,7 @@ void Server::externalJoinGameCommandReceived(const Command_JoinGame &cmd, ResponseContainer responseContainer(cmdId); Response::ResponseCode responseCode = room->processJoinGameCommand(cmd, responseContainer, userInterface); userInterface->sendResponseContainer(responseContainer, responseCode); - } catch (Response::ResponseCode code) { + } catch (Response::ResponseCode &code) { Response response; response.set_cmd_id(cmdId); response.set_response_code(code); diff --git a/common/server_player.cpp b/common/server_player.cpp index 48ae920f..19d5b77b 100644 --- a/common/server_player.cpp +++ b/common/server_player.cpp @@ -89,7 +89,7 @@ Server_Player::Server_Player(Server_Game *_game, bool _spectator, Server_AbstractUserInterface *_userInterface) : ServerInfo_User_Container(_userInfo), game(_game), userInterface(_userInterface), deck(0), pingTime(0), - playerId(_playerId), spectator(_spectator), nextCardId(0), readyStart(false), conceded(false), + playerId(_playerId), spectator(_spectator), initialCards(0), nextCardId(0), readyStart(false), conceded(false), sideboardLocked(true) { } @@ -326,7 +326,7 @@ private: int x; public: - MoveCardCompareFunctor(int _x) : x(_x) + explicit MoveCardCompareFunctor(int _x) : x(_x) { } inline bool operator()(QPair a, QPair b) @@ -451,7 +451,6 @@ Response::ResponseCode Server_Player::moveCard(GameEventStorage &ges, } } - int publicNewX; if (card->getDestroyOnZoneChange() && (startzone->getName() != targetzone->getName())) { Event_DestroyCard event; event.set_zone_name(startzone->getName().toStdString()); @@ -504,7 +503,7 @@ Response::ResponseCode Server_Player::moveCard(GameEventStorage &ges, if (startzone->getType() == ServerInfo_Zone::HiddenZone) privatePosition = position; - publicNewX = newX; + int publicNewX = newX; Event_MoveCard eventOthers; eventOthers.set_start_player_id(startzone->getPlayer()->getPlayerId()); @@ -674,7 +673,7 @@ Server_Player::cmdDeckSelect(const Command_DeckSelect &cmd, ResponseContainer &r try { newDeck = game->getRoom()->getServer()->getDatabaseInterface()->getDeckFromDatabase(cmd.deck_id(), userInfo->id()); - } catch (Response::ResponseCode r) { + } catch (Response::ResponseCode &r) { return r; } } else @@ -1600,9 +1599,8 @@ Server_Player::cmdRevealCards(const Command_RevealCards &cmd, ResponseContainer if (conceded) return Response::RespContextError; - Server_Player *otherPlayer = 0; if (cmd.has_player_id()) { - otherPlayer = game->getPlayers().value(cmd.player_id()); + Server_Player *otherPlayer = game->getPlayers().value(cmd.player_id()); if (!otherPlayer) return Response::RespNameNotFound; } diff --git a/servatrice/src/main.cpp b/servatrice/src/main.cpp index af1ad98a..ec4f8fe5 100644 --- a/servatrice/src/main.cpp +++ b/servatrice/src/main.cpp @@ -115,11 +115,6 @@ int main(int argc, char *argv[]) app.setApplicationName("Servatrice"); app.setApplicationVersion(VERSION_STRING); - bool testRandom = false; - bool testHashFunction = false; - bool logToConsole = false; - QString configPath; - QCommandLineParser parser; parser.addHelpOption(); parser.addVersionOption(); @@ -138,10 +133,10 @@ int main(int argc, char *argv[]) parser.process(app); - testRandom = parser.isSet(testRandomOpt); - testHashFunction = parser.isSet(testHashFunctionOpt); - logToConsole = parser.isSet(logToConsoleOpt); - configPath = parser.value(configPathOpt); + bool testRandom = parser.isSet(testRandomOpt); + bool testHashFunction = parser.isSet(testHashFunctionOpt); + bool logToConsole = parser.isSet(logToConsoleOpt); + QString configPath = parser.value(configPathOpt); qRegisterMetaType>("QList"); diff --git a/servatrice/src/servatrice.cpp b/servatrice/src/servatrice.cpp index 18b64262..ce587236 100644 --- a/servatrice/src/servatrice.cpp +++ b/servatrice/src/servatrice.cpp @@ -178,7 +178,9 @@ void Servatrice_IslServer::incomingConnection(qintptr socketDescriptor) QMetaObject::invokeMethod(interface, "initServer", Qt::QueuedConnection); } -Servatrice::Servatrice(QObject *parent) : Server(parent), uptime(0), shutdownTimer(0), isFirstShutdownMessage(true) +Servatrice::Servatrice(QObject *parent) + : Server(parent), authenticationMethod(AuthenticationNone), uptime(0), shutdownTimer(0), + isFirstShutdownMessage(true) { qRegisterMetaType("QSqlDatabase"); } @@ -398,7 +400,7 @@ bool Servatrice::initServer() else throw QString("islServer->listen()"); } - } catch (QString error) { + } catch (QString &error) { qDebug() << "ERROR --" << error; return false; } diff --git a/servatrice/src/servatrice_connection_pool.cpp b/servatrice/src/servatrice_connection_pool.cpp index b1b36071..353b23c8 100644 --- a/servatrice/src/servatrice_connection_pool.cpp +++ b/servatrice/src/servatrice_connection_pool.cpp @@ -3,7 +3,7 @@ #include Servatrice_ConnectionPool::Servatrice_ConnectionPool(Servatrice_DatabaseInterface *_databaseInterface) - : databaseInterface(_databaseInterface), clientCount(0) + : databaseInterface(_databaseInterface), threaded(false), clientCount(0) { } diff --git a/servatrice/src/servatrice_database_interface.cpp b/servatrice/src/servatrice_database_interface.cpp index 2ce5fff7..31f74339 100644 --- a/servatrice/src/servatrice_database_interface.cpp +++ b/servatrice/src/servatrice_database_interface.cpp @@ -1015,7 +1015,7 @@ void Servatrice_DatabaseInterface::updateUsersLastLoginData(const QString &userN } if (usersID) { - int userCount; + int userCount = 0; query = prepareQuery("select count(id) from {prefix}_user_analytics where id = :user_id"); query->bindValue(":user_id", usersID); if (!execSqlQuery(query)) diff --git a/servatrice/src/serversocketinterface.cpp b/servatrice/src/serversocketinterface.cpp index 81ee3c90..0bf0d6da 100644 --- a/servatrice/src/serversocketinterface.cpp +++ b/servatrice/src/serversocketinterface.cpp @@ -564,7 +564,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdDeckDownload(const Comm DeckList *deck; try { deck = sqlInterface->getDeckFromDatabase(cmd.deck_id(), userInfo->id()); - } catch (Response::ResponseCode r) { + } catch (Response::ResponseCode &r) { return r; } diff --git a/servatrice/src/settingscache.h b/servatrice/src/settingscache.h index 9ef992d1..7abfd8bb 100644 --- a/servatrice/src/settingscache.h +++ b/servatrice/src/settingscache.h @@ -10,7 +10,6 @@ class SettingsCache : public QSettings { Q_OBJECT private: - QSettings *settings; bool isPortableBuild; public: diff --git a/servatrice/src/signalhandler.cpp b/servatrice/src/signalhandler.cpp index e4d5d060..9fd9e486 100644 --- a/servatrice/src/signalhandler.cpp +++ b/servatrice/src/signalhandler.cpp @@ -19,7 +19,7 @@ int SignalHandler::sigHupFD[2]; -SignalHandler::SignalHandler(QObject *parent) : QObject(parent) +SignalHandler::SignalHandler(QObject *parent) : QObject(parent), snHup(nullptr) { #ifdef Q_OS_UNIX ::socketpair(AF_UNIX, SOCK_STREAM, 0, sigHupFD);