From 5519572b225fe0d20d2c8120a7249cb4c554e128 Mon Sep 17 00:00:00 2001 From: Koncord Date: Tue, 15 Jan 2019 18:45:31 +0800 Subject: [PATCH] [General] Fix warnings and errors found by PVS Studio in Server --- apps/openmw-mp/CMakeLists.txt | 2 +- apps/openmw-mp/Cell.cpp | 4 +- apps/openmw-mp/CellController.cpp | 4 +- apps/openmw-mp/CellController.hpp | 4 +- apps/openmw-mp/MasterClient.cpp | 15 +++---- apps/openmw-mp/MasterClient.hpp | 10 ++--- apps/openmw-mp/Networking.cpp | 40 +++++++++---------- apps/openmw-mp/Networking.hpp | 14 +++---- apps/openmw-mp/Player.cpp | 14 +++---- apps/openmw-mp/Player.hpp | 16 ++++---- apps/openmw-mp/Script/API/PublicFnAPI.cpp | 2 +- apps/openmw-mp/Script/API/TimerAPI.cpp | 10 ++--- apps/openmw-mp/Script/API/TimerAPI.hpp | 4 +- apps/openmw-mp/Script/Functions/Cells.cpp | 2 +- apps/openmw-mp/Script/Functions/CharClass.cpp | 2 +- apps/openmw-mp/Script/Functions/Mechanics.cpp | 2 +- apps/openmw-mp/Script/Functions/Server.cpp | 2 +- apps/openmw-mp/Script/Functions/Stats.cpp | 4 +- apps/openmw-mp/Script/LangLua/LangLua.cpp | 4 +- apps/openmw-mp/Script/LangLua/LuaFunc.cpp | 12 +++--- .../Script/LangNative/LangNative.cpp | 2 +- apps/openmw-mp/Script/ScriptFunctions.cpp | 2 +- apps/openmw-mp/Utils.cpp | 3 +- apps/openmw-mp/Utils.hpp | 2 +- apps/openmw-mp/main.cpp | 12 +++--- apps/openmw-mp/processors/ActorProcessor.cpp | 2 +- apps/openmw-mp/processors/ObjectProcessor.cpp | 2 +- .../processors/WorldstateProcessor.cpp | 2 +- components/openmw-mp/Base/BaseActor.hpp | 2 +- components/openmw-mp/Base/BaseObject.hpp | 5 ++- components/openmw-mp/Master/MasterData.hpp | 6 +-- components/openmw-mp/Packets/BasePacket.hpp | 2 +- 32 files changed, 107 insertions(+), 102 deletions(-) diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index 4ac303ef3..c4e6b8776 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -206,4 +206,4 @@ endif (MSVC) pvs_studio_add_target(TARGET tes3mp-server.analyze ALL OUTPUT FORMAT errorfile ANALYZE tes3mp-server - LOG target.err) + LOG target_tes3mp-server.err) diff --git a/apps/openmw-mp/Cell.cpp b/apps/openmw-mp/Cell.cpp index 2da4f3ea3..f6138251d 100644 --- a/apps/openmw-mp/Cell.cpp +++ b/apps/openmw-mp/Cell.cpp @@ -55,7 +55,7 @@ void Cell::addPlayer(Player *player) void Cell::removePlayer(Player *player, bool cleanPlayer) { - for (Iterator it = begin(); it != end(); it++) + for (auto it = begin(); it != end(); ++it) { if (*it == player) { @@ -161,7 +161,7 @@ void Cell::removeActors(const mwmp::BaseActorList *newActorList) } if (!foundActor) - it++; + ++it; } cellActorList.count = cellActorList.baseActors.size(); diff --git a/apps/openmw-mp/CellController.cpp b/apps/openmw-mp/CellController.cpp index 493ebd5c5..bdb3c4a87 100644 --- a/apps/openmw-mp/CellController.cpp +++ b/apps/openmw-mp/CellController.cpp @@ -64,7 +64,7 @@ Cell *CellController::getCellByXY(int x, int y) return *it; } -Cell *CellController::getCellByName(std::string cellName) +Cell *CellController::getCellByName(const std::string &cellName) { auto it = find_if(cells.begin(), cells.end(), [cellName](const Cell *c) { @@ -80,7 +80,7 @@ Cell *CellController::getCellByName(std::string cellName) return *it; } -Cell *CellController::addCell(ESM::Cell cellData) +Cell *CellController::addCell(const ESM::Cell &cellData) { LOG_APPEND(Log::LOG_INFO, "- Loaded cells: %d", cells.size()); auto it = find_if(cells.begin(), cells.end(), [cellData](const Cell *c) { diff --git a/apps/openmw-mp/CellController.hpp b/apps/openmw-mp/CellController.hpp index 7c3d5a686..477fdd902 100644 --- a/apps/openmw-mp/CellController.hpp +++ b/apps/openmw-mp/CellController.hpp @@ -27,14 +27,14 @@ public: typedef std::deque TContainer; typedef TContainer::iterator TIter; - Cell * addCell(ESM::Cell cell); + Cell * addCell(const ESM::Cell &cell); void removeCell(Cell *); void deletePlayer(Player *player); Cell *getCell(ESM::Cell *esmCell); Cell *getCellByXY(int x, int y); - Cell *getCellByName(std::string cellName); + Cell *getCellByName(const std::string &cellName); void update(Player *player); diff --git a/apps/openmw-mp/MasterClient.cpp b/apps/openmw-mp/MasterClient.cpp index a13718d42..92d96dab3 100644 --- a/apps/openmw-mp/MasterClient.cpp +++ b/apps/openmw-mp/MasterClient.cpp @@ -51,7 +51,7 @@ void MasterClient::SetMaxPlayers(unsigned pl) mutexData.unlock(); } -void MasterClient::SetHostname(std::string hostname) +void MasterClient::SetHostname(const std::string &hostname) { mutexData.lock(); string substr = hostname.substr(0, 200); @@ -63,7 +63,7 @@ void MasterClient::SetHostname(std::string hostname) mutexData.unlock(); } -void MasterClient::SetModname(std::string modname) +void MasterClient::SetModname(const std::string &modname) { mutexData.lock(); string substr = modname.substr(0, 200); @@ -75,7 +75,7 @@ void MasterClient::SetModname(std::string modname) mutexData.unlock(); } -void MasterClient::SetRuleString(std::string key, std::string value) +void MasterClient::SetRuleString(const std::string &key, std::string value) { mutexData.lock(); if (queryData.rules.find(key) == queryData.rules.end() || queryData.rules[key].type != 's' @@ -90,7 +90,7 @@ void MasterClient::SetRuleString(std::string key, std::string value) mutexData.unlock(); } -void MasterClient::SetRuleValue(std::string key, double value) +void MasterClient::SetRuleValue(const std::string &key, double value) { mutexData.lock(); if (queryData.rules.find(key) == queryData.rules.end() || queryData.rules[key].type != 'v' @@ -105,7 +105,7 @@ void MasterClient::SetRuleValue(std::string key, double value) mutexData.unlock(); } -void MasterClient::PushPlugin(Plugin plugin) +void MasterClient::PushPlugin(const Plugin &plugin) { mutexData.lock(); queryData.plugins.push_back(plugin); @@ -208,7 +208,7 @@ void MasterClient::Thread() } else { - for (int i = 0; pIt != players->end(); i++, pIt++) + for (int i = 0; pIt != players->end(); i++, ++pIt) { if (queryData.players[i] != pIt->second->npc.mName) { @@ -258,5 +258,6 @@ void MasterClient::SetUpdateRate(unsigned int rate) timeout = min_rate; else if (timeout > max_rate) timeout = max_rate; - timeout = rate; + else + timeout = rate; } diff --git a/apps/openmw-mp/MasterClient.hpp b/apps/openmw-mp/MasterClient.hpp index 858946297..b8b80be33 100644 --- a/apps/openmw-mp/MasterClient.hpp +++ b/apps/openmw-mp/MasterClient.hpp @@ -22,11 +22,11 @@ public: MasterClient(RakNet::RakPeerInterface *peer, std::string queryAddr, unsigned short queryPort); void SetPlayers(unsigned pl); void SetMaxPlayers(unsigned pl); - void SetHostname(std::string hostname); - void SetModname(std::string hostname); - void SetRuleString(std::string key, std::string value); - void SetRuleValue(std::string key, double value); - void PushPlugin(Plugin plugin); + void SetHostname(const std::string &hostname); + void SetModname(const std::string &hostname); + void SetRuleString(const std::string &key, std::string value); + void SetRuleValue(const std::string &key, double value); + void PushPlugin(const Plugin &plugin); bool Process(RakNet::Packet *packet); void Start(); diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index cb68bfa04..36f700ff0 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -75,7 +75,7 @@ Networking::~Networking() delete worldstatePacketController; } -void Networking::setServerPassword(std::string password) noexcept +void Networking::setServerPassword(const std::string &passw) noexcept { serverPassword = password.empty() ? TES3MP_DEFAULT_PASSW : password; } @@ -245,7 +245,7 @@ bool Networking::preInit(RakNet::Packet *packet, RakNet::BitStream &bsIn) auto plugin = plugins.begin(); if (samples.size() == plugins.size()) { - for (int i = 0; plugin != plugins.end(); plugin++, i++) + for (int i = 0; plugin != plugins.end(); ++plugin, i++) { LOG_APPEND(Log::LOG_VERBOSE, "- %X\t%s", plugin->second[0], plugin->first.c_str()); // Check if the filenames match, ignoring case @@ -317,7 +317,7 @@ void Networking::update(RakNet::Packet *packet, RakNet::BitStream &bsIn) LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Unhandled RakNet packet with identifier %i has arrived", packet->data[0]); } -void Networking::newPlayer(RakNet::RakNetGUID guid) +void Networking::newPlayer(const RakNet::RakNetGUID &guid) { playerPacketController->GetPacket(ID_PLAYER_BASEINFO)->RequestData(guid); playerPacketController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->RequestData(guid); @@ -327,27 +327,27 @@ void Networking::newPlayer(RakNet::RakNetGUID guid) LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Sending info about other players to %lu", guid.g); - for (TPlayers::iterator pl = players->begin(); pl != players->end(); pl++) //sending other players to new player + for (auto &player : *players) //sending other players to new player { // If we are iterating over the new player, don't send the packets below - if (pl->first == guid) continue; + if (player.first == guid) continue; // If an invalid key makes it into the Players map, ignore it - else if (pl->first == RakNet::UNASSIGNED_CRABNET_GUID) continue; + else if (player.first == RakNet::UNASSIGNED_CRABNET_GUID) continue; // if player not fully connected - else if (pl->second == nullptr) continue; + else if (player.second == nullptr) continue; // If we are iterating over a player who has inputted their name, proceed - else if (pl->second->getLoadState() == Player::POSTLOADED) + else if (player.second->getLoadState() == Player::POSTLOADED) { - playerPacketController->GetPacket(ID_PLAYER_BASEINFO)->setPlayer(pl->second); - playerPacketController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(pl->second); - playerPacketController->GetPacket(ID_PLAYER_ATTRIBUTE)->setPlayer(pl->second); - playerPacketController->GetPacket(ID_PLAYER_SKILL)->setPlayer(pl->second); - playerPacketController->GetPacket(ID_PLAYER_POSITION)->setPlayer(pl->second); - playerPacketController->GetPacket(ID_PLAYER_CELL_CHANGE)->setPlayer(pl->second); - playerPacketController->GetPacket(ID_PLAYER_EQUIPMENT)->setPlayer(pl->second); + playerPacketController->GetPacket(ID_PLAYER_BASEINFO)->setPlayer(player.second); + playerPacketController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(player.second); + playerPacketController->GetPacket(ID_PLAYER_ATTRIBUTE)->setPlayer(player.second); + playerPacketController->GetPacket(ID_PLAYER_SKILL)->setPlayer(player.second); + playerPacketController->GetPacket(ID_PLAYER_POSITION)->setPlayer(player.second); + playerPacketController->GetPacket(ID_PLAYER_CELL_CHANGE)->setPlayer(player.second); + playerPacketController->GetPacket(ID_PLAYER_EQUIPMENT)->setPlayer(player.second); playerPacketController->GetPacket(ID_PLAYER_BASEINFO)->Send(guid); playerPacketController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->Send(guid); @@ -363,7 +363,7 @@ void Networking::newPlayer(RakNet::RakNetGUID guid) } -void Networking::disconnectPlayer(RakNet::RakNetGUID guid) +void Networking::disconnectPlayer(const RakNet::RakNetGUID &guid) { Player *player = Players::getPlayer(guid); if (!player) @@ -458,7 +458,7 @@ Networking *Networking::getPtr() return sThis; } -RakNet::SystemAddress Networking::getSystemAddress(RakNet::RakNetGUID guid) +RakNet::SystemAddress Networking::getSystemAddress(const RakNet::RakNetGUID &guid) { return peer->GetSystemAddressFromGuid(guid); } @@ -538,7 +538,7 @@ int Networking::mainLoop() return exitCode; } -void Networking::kickPlayer(RakNet::RakNetGUID guid, bool sendNotification) +void Networking::kickPlayer(const RakNet::RakNetGUID &guid, bool sendNotification) { peer->CloseConnection(guid, sendNotification); } @@ -563,7 +563,7 @@ unsigned int Networking::maxConnections() const return peer->GetMaximumIncomingConnections(); } -int Networking::getAvgPing(RakNet::AddressOrGUID addr) const +int Networking::getAvgPing(const RakNet::AddressOrGUID &addr) const { return peer->GetAveragePing(addr); } @@ -578,7 +578,7 @@ MasterClient *Networking::getMasterClient() return mclient; } -void Networking::InitQuery(std::string queryAddr, unsigned short queryPort) +void Networking::InitQuery(const std::string &queryAddr, unsigned short queryPort) { mclient = new MasterClient(peer, queryAddr, queryPort); } diff --git a/apps/openmw-mp/Networking.hpp b/apps/openmw-mp/Networking.hpp index 211bc8c1c..d1e397ffd 100644 --- a/apps/openmw-mp/Networking.hpp +++ b/apps/openmw-mp/Networking.hpp @@ -17,13 +17,13 @@ namespace mwmp Networking(RakNet::RakPeerInterface *peer); ~Networking(); - void newPlayer(RakNet::RakNetGUID guid); - void disconnectPlayer(RakNet::RakNetGUID guid); - void kickPlayer(RakNet::RakNetGUID guid, bool sendNotification = true); + void newPlayer(const RakNet::RakNetGUID &guid); + void disconnectPlayer(const RakNet::RakNetGUID &guid); + void kickPlayer(const RakNet::RakNetGUID &guid, bool sendNotification = true); void banAddress(const char *ipAddress); void unbanAddress(const char *ipAddress); - RakNet::SystemAddress getSystemAddress(RakNet::RakNetGUID guid); + RakNet::SystemAddress getSystemAddress(const RakNet::RakNetGUID &guid); void processPlayerPacket(RakNet::Packet *packet); void processActorPacket(RakNet::Packet *packet); @@ -33,7 +33,7 @@ namespace mwmp unsigned short numberOfConnections() const; unsigned int maxConnections() const; - int getAvgPing(RakNet::AddressOrGUID) const; + int getAvgPing(const RakNet::AddressOrGUID &) const; unsigned short getPort() const; int mainLoop(); @@ -60,8 +60,8 @@ namespace mwmp void setScriptErrorIgnoringState(bool state); MasterClient *getMasterClient(); - void InitQuery(std::string queryAddr, unsigned short queryPort); - void setServerPassword(std::string passw) noexcept; + void InitQuery(const std::string &queryAddr, unsigned short queryPort); + void setServerPassword(const std::string &passw) noexcept; bool isPassworded() const; static const Networking &get(); diff --git a/apps/openmw-mp/Player.cpp b/apps/openmw-mp/Player.cpp index 296496702..d0171acd3 100644 --- a/apps/openmw-mp/Player.cpp +++ b/apps/openmw-mp/Player.cpp @@ -10,7 +10,7 @@ TSlots Players::slots; using namespace std; -void Players::deletePlayer(RakNet::RakNetGUID guid) +void Players::deletePlayer(const RakNet::RakNetGUID &guid) { LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Deleting player with guid %lu", guid.g); @@ -26,7 +26,7 @@ void Players::deletePlayer(RakNet::RakNetGUID guid) } } -void Players::newPlayer(RakNet::RakNetGUID guid) +void Players::newPlayer(const RakNet::RakNetGUID &guid) { LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Creating new player with guid %lu", guid.g); @@ -41,7 +41,7 @@ void Players::newPlayer(RakNet::RakNetGUID guid) for (unsigned int i = 0; i < mwmp::Networking::get().maxConnections(); i++) { - if (slots[i] == 0) + if (slots[i] == nullptr) { LOG_APPEND(Log::LOG_INFO, "- Storing in slot %i", i); @@ -52,7 +52,7 @@ void Players::newPlayer(RakNet::RakNetGUID guid) } } -Player *Players::getPlayer(RakNet::RakNetGUID guid) +Player *Players::getPlayer(const RakNet::RakNetGUID &guid) { auto it = players.find(guid); if (it == players.end()) @@ -70,7 +70,7 @@ unsigned short Players::getLastPlayerId() return slots.rbegin()->first; } -Player::Player(RakNet::RakNetGUID guid) : BasePlayer(guid) +Player::Player(const RakNet::RakNetGUID &guid) : BasePlayer(guid), id(InvalidID) { handshakeCounter = 0; loadState = NOTLOADED; @@ -81,7 +81,7 @@ Player::~Player() } -unsigned short Player::getId() +unsigned int Player::getId() { return id; } @@ -177,7 +177,7 @@ void Player::forEachLoaded(std::function func) } } -bool Players::doesPlayerExist(RakNet::RakNetGUID guid) +bool Players::doesPlayerExist(const RakNet::RakNetGUID &guid) { return players.find(guid) != players.end(); } diff --git a/apps/openmw-mp/Player.hpp b/apps/openmw-mp/Player.hpp index a59319f3b..1aa83985f 100644 --- a/apps/openmw-mp/Player.hpp +++ b/apps/openmw-mp/Player.hpp @@ -28,13 +28,13 @@ typedef std::map TSlots; class Players { public: - static void newPlayer(RakNet::RakNetGUID guid); - static void deletePlayer(RakNet::RakNetGUID guid); - static Player *getPlayer(RakNet::RakNetGUID guid); + static void newPlayer(const RakNet::RakNetGUID &guid); + static void deletePlayer(const RakNet::RakNetGUID &guid); + static Player *getPlayer(const RakNet::RakNetGUID &guid); static Player *getPlayer(unsigned short id); static TPlayers *getPlayers(); static unsigned short getLastPlayerId(); - static bool doesPlayerExist(RakNet::RakNetGUID guid); + static bool doesPlayerExist(const RakNet::RakNetGUID &guid); private: static TPlayers players; @@ -44,9 +44,8 @@ private: class Player : public mwmp::BasePlayer { friend class Cell; - unsigned short id; public: - + const unsigned int InvalidID = (unsigned int) -1; enum { NOTLOADED=0, @@ -54,9 +53,9 @@ public: POSTLOADED, KICKED }; - Player(RakNet::RakNetGUID guid); + Player(const RakNet::RakNetGUID &guid); - unsigned short getId(); + unsigned int getId(); void setId(unsigned short id); bool isHandshaked(); @@ -78,6 +77,7 @@ private: CellController::TContainer cells; int loadState; int handshakeCounter; + unsigned int id; }; diff --git a/apps/openmw-mp/Script/API/PublicFnAPI.cpp b/apps/openmw-mp/Script/API/PublicFnAPI.cpp index c0bc713d8..f1fc6de9f 100644 --- a/apps/openmw-mp/Script/API/PublicFnAPI.cpp +++ b/apps/openmw-mp/Script/API/PublicFnAPI.cpp @@ -61,7 +61,7 @@ bool Public::IsLua(const std::string &name) void Public::DeleteAll() { - for (auto it = publics.begin(); it != publics.end(); it++) + for (auto it = publics.begin(); it != publics.end(); ++it) { Public *_public = it->second; delete _public; diff --git a/apps/openmw-mp/Script/API/TimerAPI.cpp b/apps/openmw-mp/Script/API/TimerAPI.cpp index e4275d927..2c096efa6 100644 --- a/apps/openmw-mp/Script/API/TimerAPI.cpp +++ b/apps/openmw-mp/Script/API/TimerAPI.cpp @@ -6,18 +6,18 @@ using namespace mwmp; using namespace std; -Timer::Timer(ScriptFunc callback, long msec, const std::string& def, std::vector args) : ScriptFunction(callback, 'v', def) +Timer::Timer(ScriptFunc callback, long msec, const std::string& def, std::vector args) : ScriptFunction(callback, 'v', def), args(args) { + startTime = 0; targetMsec = msec; - this->args = args; isEnded = true; } #if defined(ENABLE_LUA) -Timer::Timer(lua_State *lua, ScriptFuncLua callback, long msec, const std::string& def, std::vector args): ScriptFunction(callback, lua, 'v', def) +Timer::Timer(lua_State *lua, ScriptFuncLua callback, long msec, const std::string& def, std::vector args): ScriptFunction(callback, lua, 'v', def), args(args) { + startTime = 0; targetMsec = msec; - this->args = args; isEnded = true; } #endif @@ -90,7 +90,7 @@ int TimerAPI::CreateTimerLua(lua_State *lua, ScriptFuncLua callback, long msec, #endif -int TimerAPI::CreateTimer(ScriptFunc callback, long msec, const std::string &def, std::vector args) +int TimerAPI::CreateTimer(ScriptFunc callback, long msec, const std::string &def, const std::vector &args) { int id = -1; diff --git a/apps/openmw-mp/Script/API/TimerAPI.hpp b/apps/openmw-mp/Script/API/TimerAPI.hpp index 83b6baba4..4db744678 100644 --- a/apps/openmw-mp/Script/API/TimerAPI.hpp +++ b/apps/openmw-mp/Script/API/TimerAPI.hpp @@ -29,9 +29,9 @@ namespace mwmp void Restart(int msec); private: double startTime, targetMsec; - std::string publ, arg_types; + //std::string publ, arg_types; std::vector args; - Script *scr; + //Script *scr; bool isEnded; }; diff --git a/apps/openmw-mp/Script/Functions/Cells.cpp b/apps/openmw-mp/Script/Functions/Cells.cpp index c78198fba..b497dbd2f 100644 --- a/apps/openmw-mp/Script/Functions/Cells.cpp +++ b/apps/openmw-mp/Script/Functions/Cells.cpp @@ -45,7 +45,7 @@ extern "C" const char *CellFunctions::GetCell(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player, 0); - tempCellDescription = player->cell.getDescription().c_str(); + tempCellDescription = player->cell.getDescription(); return tempCellDescription.c_str(); } diff --git a/apps/openmw-mp/Script/Functions/CharClass.cpp b/apps/openmw-mp/Script/Functions/CharClass.cpp index f5243b94b..64bdb78ec 100644 --- a/apps/openmw-mp/Script/Functions/CharClass.cpp +++ b/apps/openmw-mp/Script/Functions/CharClass.cpp @@ -99,7 +99,7 @@ extern "C" void CharClassFunctions::SetClassName(unsigned short pid, const char GET_PLAYER(pid, player,); player->charClass.mName = name; - player->charClass.mId = ""; + player->charClass.mId.clear(); } extern "C" void CharClassFunctions::SetClassDesc(unsigned short pid, const char *desc) noexcept diff --git a/apps/openmw-mp/Script/Functions/Mechanics.cpp b/apps/openmw-mp/Script/Functions/Mechanics.cpp index f10ed0dd7..7d04159f8 100644 --- a/apps/openmw-mp/Script/Functions/Mechanics.cpp +++ b/apps/openmw-mp/Script/Functions/Mechanics.cpp @@ -24,7 +24,7 @@ extern "C" const char *MechanicsFunctions::GetMarkCell(unsigned short pid) noexc Player *player; GET_PLAYER(pid, player, 0); - tempCellDescription = player->cell.getDescription().c_str(); + tempCellDescription = player->cell.getDescription(); return tempCellDescription.c_str(); } diff --git a/apps/openmw-mp/Script/Functions/Server.cpp b/apps/openmw-mp/Script/Functions/Server.cpp index 5bef7765e..c83bc4450 100644 --- a/apps/openmw-mp/Script/Functions/Server.cpp +++ b/apps/openmw-mp/Script/Functions/Server.cpp @@ -151,7 +151,7 @@ extern "C" void ServerFunctions::AddPluginHash(const char *pluginName, const cha unsigned hash = 0; - if (strlen(hashStr) != 0) + if (hashStr[0] != '\0') { hash = (unsigned) std::stoul(hashStr); hashList.push_back(hash); diff --git a/apps/openmw-mp/Script/Functions/Stats.cpp b/apps/openmw-mp/Script/Functions/Stats.cpp index 8ff3a04a0..ef19b207e 100644 --- a/apps/openmw-mp/Script/Functions/Stats.cpp +++ b/apps/openmw-mp/Script/Functions/Stats.cpp @@ -239,7 +239,7 @@ extern "C" int StatsFunctions::GetSkillIncrease(unsigned short pid, unsigned int Player *player; GET_PLAYER(pid, player, 0); - if (attributeId > Attribute::Length) + if (attributeId >= Attribute::Length) return 0; return player->npcStats.mSkillIncrease[attributeId]; @@ -484,7 +484,7 @@ extern "C" void StatsFunctions::SetSkillIncrease(unsigned short pid, unsigned in Player *player; GET_PLAYER(pid, player,); - if (attributeId > Attribute::Length) + if (attributeId >= Attribute::Length) return; player->npcStats.mSkillIncrease[attributeId] = value; diff --git a/apps/openmw-mp/Script/LangLua/LangLua.cpp b/apps/openmw-mp/Script/LangLua/LangLua.cpp index f813776e8..4ef93e219 100644 --- a/apps/openmw-mp/Script/LangLua/LangLua.cpp +++ b/apps/openmw-mp/Script/LangLua/LangLua.cpp @@ -252,7 +252,7 @@ boost::any LangLua::Call(const char *name, const char *argl, int buf, ...) break; default: - throw runtime_error("C++ call: Unknown argument identifier " + argl[index]); + throw runtime_error(std::string("C++ call: Unknown argument identifier ") + argl[index]); } } @@ -304,7 +304,7 @@ boost::any LangLua::Call(const char *name, const char *argl, const std::vector::push(lua, boost::any_cast(args.at(index))); break; default: - throw runtime_error("Lua call: Unknown argument identifier " + argl[index]); + throw runtime_error(std::string("Lua call: Unknown argument identifier ") + argl[index]); } } diff --git a/apps/openmw-mp/Script/LangLua/LuaFunc.cpp b/apps/openmw-mp/Script/LangLua/LuaFunc.cpp index 64fca01d7..e7b90a48b 100644 --- a/apps/openmw-mp/Script/LangLua/LuaFunc.cpp +++ b/apps/openmw-mp/Script/LangLua/LuaFunc.cpp @@ -9,7 +9,7 @@ using namespace std; -inline vector DefToVec(lua_State *lua, string types, int args_begin, int args_n) +inline vector DefToVec(lua_State *lua, const string &types, int args_begin, int args_n) { vector args; @@ -93,13 +93,15 @@ int LangLua::CallPublic(lua_State *lua) if (result.empty()) return 0; - if (result.type().hash_code() == typeid(signed int).hash_code()) + auto retTypeHash = result.type().hash_code(); + + if (retTypeHash == typeid(signed int).hash_code()) luabridge::Stack::push(lua, boost::any_cast(result)); - else if (result.type().hash_code() == typeid(unsigned int).hash_code()) + else if (retTypeHash == typeid(unsigned int).hash_code()) luabridge::Stack::push(lua, boost::any_cast(result)); - else if (result.type().hash_code() == typeid(double).hash_code()) + else if (retTypeHash == typeid(double).hash_code()) luabridge::Stack::push(lua, boost::any_cast(result)); - else if (result.type().hash_code() == typeid(const char*).hash_code()) + else if (retTypeHash == typeid(const char*).hash_code()) luabridge::Stack::push(lua, boost::any_cast(result)); return 1; } diff --git a/apps/openmw-mp/Script/LangNative/LangNative.cpp b/apps/openmw-mp/Script/LangNative/LangNative.cpp index 616557eb0..616ddd44e 100644 --- a/apps/openmw-mp/Script/LangNative/LangNative.cpp +++ b/apps/openmw-mp/Script/LangNative/LangNative.cpp @@ -91,7 +91,7 @@ lib_t LangNative::GetInterface() } -LangNative::LangNative() +LangNative::LangNative(): lib(nullptr) { } diff --git a/apps/openmw-mp/Script/ScriptFunctions.cpp b/apps/openmw-mp/Script/ScriptFunctions.cpp index d88c2f29e..0967685e3 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.cpp +++ b/apps/openmw-mp/Script/ScriptFunctions.cpp @@ -56,7 +56,7 @@ void ScriptFunctions::GetArguments(std::vector ¶ms, va_list args break; default: - throw runtime_error("C++ call: Unknown argument identifier " + c); + throw runtime_error(std::string("C++ call: Unknown argument identifier ") + c); } } } diff --git a/apps/openmw-mp/Utils.cpp b/apps/openmw-mp/Utils.cpp index d5d621e49..fc282f494 100644 --- a/apps/openmw-mp/Utils.cpp +++ b/apps/openmw-mp/Utils.cpp @@ -17,7 +17,6 @@ const vector Utils::split(const string &str, int delimiter) else if (!buffer.empty()) { result.push_back(move(buffer)); - buffer.clear(); } if (!buffer.empty()) result.push_back(move(buffer)); @@ -25,7 +24,7 @@ const vector Utils::split(const string &str, int delimiter) return result; } -ESM::Cell Utils::getCellFromDescription(std::string cellDescription) +ESM::Cell Utils::getCellFromDescription(const std::string &cellDescription) { ESM::Cell cell; cell.blank(); diff --git a/apps/openmw-mp/Utils.hpp b/apps/openmw-mp/Utils.hpp index b511a5b10..5093ce6ed 100644 --- a/apps/openmw-mp/Utils.hpp +++ b/apps/openmw-mp/Utils.hpp @@ -25,7 +25,7 @@ namespace Utils { const std::vector split(const std::string &str, int delimiter); - ESM::Cell getCellFromDescription(std::string cellDescription); + ESM::Cell getCellFromDescription(const std::string &cellDescription); template constexpr unsigned int hash(const char(&str)[N], size_t I = N) diff --git a/apps/openmw-mp/main.cpp b/apps/openmw-mp/main.cpp index 6a74808f1..123858db8 100644 --- a/apps/openmw-mp/main.cpp +++ b/apps/openmw-mp/main.cpp @@ -309,13 +309,15 @@ int main(int argc, char *argv[]) } networking.InitQuery(masterAddr, (unsigned short) masterPort); - networking.getMasterClient()->SetMaxPlayers((unsigned) players); - networking.getMasterClient()->SetUpdateRate((unsigned) updateRate); + auto masterClient = networking.getMasterClient(); + + masterClient->SetMaxPlayers((unsigned) players); + masterClient->SetUpdateRate((unsigned) updateRate); string hostname = mgr.getString("hostname", "General"); - networking.getMasterClient()->SetHostname(hostname); - networking.getMasterClient()->SetRuleString("CommitHash", version.mCommitHash.substr(0, 10)); + masterClient->SetHostname(hostname); + masterClient->SetRuleString("CommitHash", version.mCommitHash.substr(0, 10)); - networking.getMasterClient()->Start(); + masterClient->Start(); } networking.postInit(); diff --git a/apps/openmw-mp/processors/ActorProcessor.cpp b/apps/openmw-mp/processors/ActorProcessor.cpp index b7a68d832..f148e7438 100644 --- a/apps/openmw-mp/processors/ActorProcessor.cpp +++ b/apps/openmw-mp/processors/ActorProcessor.cpp @@ -31,7 +31,7 @@ bool ActorProcessor::Process(RakNet::Packet &packet, BaseActorList &actorList) n if (!processor.second->avoidReading) myPacket->Read(); - if (actorList.isValid) + if (actorList.isValid) // -V547 processor.second->Do(*myPacket, *player, actorList); else LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Received %s that failed integrity check and was ignored!", processor.second->strPacketID.c_str()); diff --git a/apps/openmw-mp/processors/ObjectProcessor.cpp b/apps/openmw-mp/processors/ObjectProcessor.cpp index cc451a813..1a634b2d5 100644 --- a/apps/openmw-mp/processors/ObjectProcessor.cpp +++ b/apps/openmw-mp/processors/ObjectProcessor.cpp @@ -31,7 +31,7 @@ bool ObjectProcessor::Process(RakNet::Packet &packet, BaseObjectList &objectList if (!processor.second->avoidReading) myPacket->Read(); - if (objectList.isValid) + if (objectList.isValid) // -V547 processor.second->Do(*myPacket, *player, objectList); else LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Received %s that failed integrity check and was ignored!", processor.second->strPacketID.c_str()); diff --git a/apps/openmw-mp/processors/WorldstateProcessor.cpp b/apps/openmw-mp/processors/WorldstateProcessor.cpp index cbe4e010b..9daa937b3 100644 --- a/apps/openmw-mp/processors/WorldstateProcessor.cpp +++ b/apps/openmw-mp/processors/WorldstateProcessor.cpp @@ -28,7 +28,7 @@ bool WorldstateProcessor::Process(RakNet::Packet &packet, BaseWorldstate &worlds if (!processor.second->avoidReading) myPacket->Read(); - if (worldstate.isValid) + if (worldstate.isValid) // -V547 processor.second->Do(*myPacket, *player, worldstate); else LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Received %s that failed integrity check and was ignored!", processor.second->strPacketID.c_str()); diff --git a/components/openmw-mp/Base/BaseActor.hpp b/components/openmw-mp/Base/BaseActor.hpp index 030322081..edf46e0ff 100644 --- a/components/openmw-mp/Base/BaseActor.hpp +++ b/components/openmw-mp/Base/BaseActor.hpp @@ -61,7 +61,7 @@ namespace mwmp { public: - BaseActorList() + BaseActorList(): count(0), action(0), isValid(false) { } diff --git a/components/openmw-mp/Base/BaseObject.hpp b/components/openmw-mp/Base/BaseObject.hpp index 01e229200..2fc0cbf1b 100644 --- a/components/openmw-mp/Base/BaseObject.hpp +++ b/components/openmw-mp/Base/BaseObject.hpp @@ -81,12 +81,13 @@ namespace mwmp { public: - BaseObjectList(RakNet::RakNetGUID guid) : guid(guid) + BaseObjectList(RakNet::RakNetGUID guid) : guid(guid), baseObjectCount(0), packetOrigin(0), action(0), + containerSubAction(0), isValid(false) { } - BaseObjectList() + BaseObjectList(): baseObjectCount(0), packetOrigin(0), action(0), containerSubAction(0), isValid(false) { } diff --git a/components/openmw-mp/Master/MasterData.hpp b/components/openmw-mp/Master/MasterData.hpp index ef85e1adc..a55f2eba4 100644 --- a/components/openmw-mp/Master/MasterData.hpp +++ b/components/openmw-mp/Master/MasterData.hpp @@ -43,15 +43,15 @@ struct QueryData QueryData() { rules["name"].type = ServerRule::Type::string; - rules["name"].str = ""; + rules["name"].str.clear(); rules["version"].type = ServerRule::Type::string; - rules["version"].str = ""; + rules["version"].str.clear(); rules["players"].type = ServerRule::Type::number; rules["players"].val = 0; rules["maxPlayers"].type = ServerRule::Type::number; rules["maxPlayers"].val = 0; rules["gamemode"].type = ServerRule::Type::string; - rules["gamemode"].str = ""; + rules["gamemode"].str.clear(); rules["passw"].type = ServerRule::Type::number; rules["passw"].val = 0; } diff --git a/components/openmw-mp/Packets/BasePacket.hpp b/components/openmw-mp/Packets/BasePacket.hpp index 1d1ed0eeb..bcf41b73d 100644 --- a/components/openmw-mp/Packets/BasePacket.hpp +++ b/components/openmw-mp/Packets/BasePacket.hpp @@ -114,7 +114,7 @@ namespace mwmp str = rstr.C_String(); } else - str = std::string(); + str.clear(); } return res; }