From b8beb4fb13bdb30126363ec493512b888f7ddeb0 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sat, 1 Jun 2024 11:48:30 +0000 Subject: [PATCH] Fixes for various minor issues detected by Sonar Cloud --- AI/Nullkiller/AIGateway.cpp | 10 +++++----- AI/Nullkiller/Engine/Nullkiller.cpp | 4 ++-- AI/Nullkiller/Pathfinding/Actors.cpp | 4 ++-- AI/VCAI/VCAI.cpp | 4 ++-- client/CPlayerInterface.cpp | 2 +- client/CServerHandler.cpp | 2 +- client/Client.cpp | 2 +- client/ConditionalWait.h | 9 ++++----- client/adventureMap/AdventureMapShortcuts.cpp | 2 +- client/adventureMap/AdventureMapShortcuts.h | 2 +- client/battle/BattleInterfaceClasses.cpp | 2 +- client/battle/BattleInterfaceClasses.h | 2 +- client/battle/BattleWindow.cpp | 2 +- client/lobby/CSelectionBase.cpp | 2 +- client/lobby/SelectionTab.cpp | 2 +- client/mainmenu/CHighScoreScreen.cpp | 8 ++++---- client/widgets/CTextInput.cpp | 3 +-- client/widgets/CTextInput.h | 3 +-- client/windows/CCastleInterface.cpp | 6 +++--- client/windows/CHeroWindow.cpp | 2 +- client/windows/GUIClasses.cpp | 4 ++-- lib/CGeneralTextHandler.cpp | 20 +++++++++---------- lib/CPlayerState.h | 2 +- lib/CSkillHandler.cpp | 2 +- lib/network/NetworkConnection.cpp | 4 ++-- lib/networkPacks/PacksForLobby.h | 2 +- lib/rmg/PenroseTiling.cpp | 4 ++-- mapeditor/graphics.cpp | 2 +- server/CVCMIServer.cpp | 6 +++--- 29 files changed, 58 insertions(+), 61 deletions(-) diff --git a/AI/Nullkiller/AIGateway.cpp b/AI/Nullkiller/AIGateway.cpp index ecbffca42..0d365859c 100644 --- a/AI/Nullkiller/AIGateway.cpp +++ b/AI/Nullkiller/AIGateway.cpp @@ -603,7 +603,7 @@ void AIGateway::heroGotLevel(const CGHeroInstance * hero, PrimarySkill pskill, s if(hPtr.validAndSet()) { - std::unique_lock lockGuard(nullkiller->aiStateMutex); + std::unique_lock lockGuard(nullkiller->aiStateMutex); nullkiller->heroManager->update(); @@ -683,7 +683,7 @@ void AIGateway::showBlockingDialog(const std::string & text, const std::vector mxLock(nullkiller->aiStateMutex); + std::unique_lock mxLock(nullkiller->aiStateMutex); // TODO: Find better way to understand it is Chest of Treasures if(hero.validAndSet() @@ -804,7 +804,7 @@ void AIGateway::makeTurn() auto day = cb->getDate(Date::DAY); logAi->info("Player %d (%s) starting turn, day %d", playerID, playerID.toString(), day); - boost::shared_lock gsLock(CGameState::mutex); + boost::shared_lock gsLock(CGameState::mutex); setThreadName("AIGateway::makeTurn"); if(nullkiller->isOpenMap()) @@ -864,7 +864,7 @@ void AIGateway::performObjectInteraction(const CGObjectInstance * obj, HeroPtr h { makePossibleUpgrades(h.get()); - std::unique_lock lockGuard(nullkiller->aiStateMutex); + std::unique_lock lockGuard(nullkiller->aiStateMutex); if(!h->visitedTown->garrisonHero || !nullkiller->isHeroLocked(h->visitedTown->garrisonHero)) moveCreaturesToHero(h->visitedTown); @@ -1529,7 +1529,7 @@ void AIGateway::requestActionASAP(std::function whatToDo) { setThreadName("AIGateway::requestActionASAP::whatToDo"); SET_GLOBAL_STATE(this); - boost::shared_lock gsLock(CGameState::mutex); + boost::shared_lock gsLock(CGameState::mutex); whatToDo(); }); diff --git a/AI/Nullkiller/Engine/Nullkiller.cpp b/AI/Nullkiller/Engine/Nullkiller.cpp index bddcad681..ea26b96ff 100644 --- a/AI/Nullkiller/Engine/Nullkiller.cpp +++ b/AI/Nullkiller/Engine/Nullkiller.cpp @@ -216,7 +216,7 @@ void Nullkiller::decompose(Goals::TGoalVec & result, Goals::TSubgoal behavior, i void Nullkiller::resetAiState() { - std::unique_lock lockGuard(aiStateMutex); + std::unique_lock lockGuard(aiStateMutex); lockedResources = TResources(); scanDepth = ScanDepth::MAIN_FULL; @@ -236,7 +236,7 @@ void Nullkiller::updateAiState(int pass, bool fast) { boost::this_thread::interruption_point(); - std::unique_lock lockGuard(aiStateMutex); + std::unique_lock lockGuard(aiStateMutex); auto start = std::chrono::high_resolution_clock::now(); diff --git a/AI/Nullkiller/Pathfinding/Actors.cpp b/AI/Nullkiller/Pathfinding/Actors.cpp index cccd55a57..ae6b6446e 100644 --- a/AI/Nullkiller/Pathfinding/Actors.cpp +++ b/AI/Nullkiller/Pathfinding/Actors.cpp @@ -217,7 +217,7 @@ ExchangeResult HeroExchangeMap::tryExchangeNoLock(const ChainActor * other) ExchangeResult result; { - boost::shared_lock lock(sync, boost::try_to_lock); + boost::shared_lock lock(sync, boost::try_to_lock); if(!lock.owns_lock()) { @@ -237,7 +237,7 @@ ExchangeResult HeroExchangeMap::tryExchangeNoLock(const ChainActor * other) } { - boost::unique_lock uniqueLock(sync, boost::try_to_lock); + boost::unique_lock uniqueLock(sync, boost::try_to_lock); if(!uniqueLock.owns_lock()) { diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index 924b2818a..8484edb54 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -773,7 +773,7 @@ void VCAI::makeTurn() auto day = cb->getDate(Date::DAY); logAi->info("Player %d (%s) starting turn, day %d", playerID, playerID.toString(), day); - boost::shared_lock gsLock(CGameState::mutex); + boost::shared_lock gsLock(CGameState::mutex); setThreadName("VCAI::makeTurn"); switch(cb->getDate(Date::DAY_OF_WEEK)) @@ -2479,7 +2479,7 @@ void VCAI::requestActionASAP(std::function whatToDo) { setThreadName("VCAI::requestActionASAP::whatToDo"); SET_GLOBAL_STATE(this); - boost::shared_lock gsLock(CGameState::mutex); + boost::shared_lock gsLock(CGameState::mutex); whatToDo(); }); diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 2d94892fd..6827e1546 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -1481,7 +1481,7 @@ void CPlayerInterface::playerBlocked(int reason, bool start) void CPlayerInterface::update() { // Make sure that gamestate won't change when GUI objects may obtain its parts on event processing or drawing request - boost::shared_lock gsLock(CGameState::mutex); + boost::shared_lock gsLock(CGameState::mutex); // While mutexes were locked away we may be have stopped being the active interface if (LOCPLINT != this) diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index 2ee59e171..3a7ca9b1f 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -173,7 +173,7 @@ void CServerHandler::threadRunNetwork() try { networkHandler->run(); } - catch (const TerminationRequestedException & e) + catch (const TerminationRequestedException &) { logGlobal->info("Terminating network thread"); return; diff --git a/client/Client.cpp b/client/Client.cpp index 76ea9a120..b3fff6f01 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -408,7 +408,7 @@ void CClient::handlePack(CPack * pack) apply->applyOnClBefore(this, pack); logNetwork->trace("\tMade first apply on cl: %s", typeid(*pack).name()); { - boost::unique_lock lock(CGameState::mutex); + boost::unique_lock lock(CGameState::mutex); gs->apply(pack); } logNetwork->trace("\tApplied on gs: %s", typeid(*pack).name()); diff --git a/client/ConditionalWait.h b/client/ConditionalWait.h index 0df2de789..22262fade 100644 --- a/client/ConditionalWait.h +++ b/client/ConditionalWait.h @@ -33,7 +33,7 @@ class ConditionalWait void set(bool value) { - boost::unique_lock lock(mx); + std::unique_lock lock(mx); isBusyValue = value; } @@ -59,15 +59,14 @@ public: bool isBusy() { - std::unique_lock lock(mx); + std::unique_lock lock(mx); return isBusyValue; } void waitWhileBusy() { - std::unique_lock un(mx); - while(isBusyValue) - cond.wait(un); + std::unique_lock un(mx); + cond.wait(un, [this](){ return !isBusyValue;}); if (isTerminating) throw TerminationRequestedException(); diff --git a/client/adventureMap/AdventureMapShortcuts.cpp b/client/adventureMap/AdventureMapShortcuts.cpp index 5cc33fc28..2db16f04b 100644 --- a/client/adventureMap/AdventureMapShortcuts.cpp +++ b/client/adventureMap/AdventureMapShortcuts.cpp @@ -48,7 +48,7 @@ void AdventureMapShortcuts::setState(EAdventureState newState) state = newState; } -EAdventureState AdventureMapShortcuts::getState() +EAdventureState AdventureMapShortcuts::getState() const { return state; } diff --git a/client/adventureMap/AdventureMapShortcuts.h b/client/adventureMap/AdventureMapShortcuts.h index 8682bf82d..7b1e1ec7d 100644 --- a/client/adventureMap/AdventureMapShortcuts.h +++ b/client/adventureMap/AdventureMapShortcuts.h @@ -94,6 +94,6 @@ public: bool optionMapViewActive(); void setState(EAdventureState newState); - EAdventureState getState(); + EAdventureState getState() const; void onMapViewMoved(const Rect & visibleArea, int mapLevel); }; diff --git a/client/battle/BattleInterfaceClasses.cpp b/client/battle/BattleInterfaceClasses.cpp index 1ad8cca65..d6e2ca161 100644 --- a/client/battle/BattleInterfaceClasses.cpp +++ b/client/battle/BattleInterfaceClasses.cpp @@ -72,7 +72,7 @@ void BattleConsole::showAll(Canvas & to) to.drawText(line2, FONT_SMALL, Colors::WHITE, ETextAlignment::CENTER, visibleText[1]); } -std::vector BattleConsole::getVisibleText() +std::vector BattleConsole::getVisibleText() const { // high priority texts that hide battle log entries for(const auto & text : {consoleText, hoverText}) diff --git a/client/battle/BattleInterfaceClasses.h b/client/battle/BattleInterfaceClasses.h index 6b9762d62..c385db754 100644 --- a/client/battle/BattleInterfaceClasses.h +++ b/client/battle/BattleInterfaceClasses.h @@ -72,7 +72,7 @@ private: std::vector splitText(const std::string &text); /// select line(s) that will be visible in UI - std::vector getVisibleText(); + std::vector getVisibleText() const; public: BattleConsole(const BattleInterface & owner, std::shared_ptr backgroundSource, const Point & objectPos, const Point & imagePos, const Point &size); diff --git a/client/battle/BattleWindow.cpp b/client/battle/BattleWindow.cpp index ddc8b88d2..352be3a5c 100644 --- a/client/battle/BattleWindow.cpp +++ b/client/battle/BattleWindow.cpp @@ -773,7 +773,7 @@ void BattleWindow::bOpenActiveUnit() const auto * unit = owner.stacksController->getActiveStack(); if (unit) - GH.windows().createAndPushWindow(unit, false);; + GH.windows().createAndPushWindow(unit, false); } void BattleWindow::bOpenHoveredUnit() diff --git a/client/lobby/CSelectionBase.cpp b/client/lobby/CSelectionBase.cpp index 52b346094..558aa3662 100644 --- a/client/lobby/CSelectionBase.cpp +++ b/client/lobby/CSelectionBase.cpp @@ -478,7 +478,7 @@ void TownSelector::updateListItems() { if(y >= line && (y - line) < 3) { - auto getImageIndex = [](FactionID factionID, bool enabled){ return factionID.toFaction()->town->clientInfo.icons[true][!enabled] + 2; }; + auto getImageIndex = [](FactionID targetFactionID, bool enabled){ return targetFactionID.toFaction()->town->clientInfo.icons[true][!enabled] + 2; }; towns[factionID] = std::make_shared(AnimationPath::builtin("ITPA"), getImageIndex(factionID, townsEnabled[factionID]), 0, x_offset + 48 * x, 32 * (y - line)); townsArea[factionID] = std::make_shared(Rect(x_offset + 48 * x, 32 * (y - line), 48, 32), [this, getImageIndex, factionID](){ townsEnabled[factionID] = !townsEnabled[factionID]; diff --git a/client/lobby/SelectionTab.cpp b/client/lobby/SelectionTab.cpp index 6711419f0..918bfc8cd 100644 --- a/client/lobby/SelectionTab.cpp +++ b/client/lobby/SelectionTab.cpp @@ -698,7 +698,7 @@ void SelectionTab::selectNewestFile() { time_t newestTime = 0; std::string newestFile = ""; - for(int i = (int)allItems.size() - 1; i >= 0; i--) + for(int i = static_cast(allItems.size()) - 1; i >= 0; i--) if(allItems[i]->lastWrite > newestTime) { newestTime = allItems[i]->lastWrite; diff --git a/client/mainmenu/CHighScoreScreen.cpp b/client/mainmenu/CHighScoreScreen.cpp index da8df3cfb..62ab5f4b5 100644 --- a/client/mainmenu/CHighScoreScreen.cpp +++ b/client/mainmenu/CHighScoreScreen.cpp @@ -112,10 +112,10 @@ void CHighScoreScreen::addButtons() buttons.clear(); - buttons.push_back(std::make_shared(Point(31, 113), AnimationPath::builtin("HISCCAM.DEF"), CButton::tooltip(), [&](){ buttonCampaignClick(); }, EShortcut::HIGH_SCORES_CAMPAIGNS)); - buttons.push_back(std::make_shared(Point(31, 345), AnimationPath::builtin("HISCSTA.DEF"), CButton::tooltip(), [&](){ buttonScenarioClick(); }, EShortcut::HIGH_SCORES_SCENARIOS)); - buttons.push_back(std::make_shared(Point(726, 113), AnimationPath::builtin("HISCRES.DEF"), CButton::tooltip(), [&](){ buttonResetClick(); }, EShortcut::HIGH_SCORES_RESET)); - buttons.push_back(std::make_shared(Point(726, 345), AnimationPath::builtin("HISCEXT.DEF"), CButton::tooltip(), [&](){ buttonExitClick(); }, EShortcut::GLOBAL_RETURN)); + buttons.push_back(std::make_shared(Point(31, 113), AnimationPath::builtin("HISCCAM.DEF"), CButton::tooltip(), [this](){ buttonCampaignClick(); }, EShortcut::HIGH_SCORES_CAMPAIGNS)); + buttons.push_back(std::make_shared(Point(31, 345), AnimationPath::builtin("HISCSTA.DEF"), CButton::tooltip(), [this](){ buttonScenarioClick(); }, EShortcut::HIGH_SCORES_SCENARIOS)); + buttons.push_back(std::make_shared(Point(726, 113), AnimationPath::builtin("HISCRES.DEF"), CButton::tooltip(), [this](){ buttonResetClick(); }, EShortcut::HIGH_SCORES_RESET)); + buttons.push_back(std::make_shared(Point(726, 345), AnimationPath::builtin("HISCEXT.DEF"), CButton::tooltip(), [this](){ buttonExitClick(); }, EShortcut::GLOBAL_RETURN)); } void CHighScoreScreen::addHighScores() diff --git a/client/widgets/CTextInput.cpp b/client/widgets/CTextInput.cpp index 938a739a8..5aefa2598 100644 --- a/client/widgets/CTextInput.cpp +++ b/client/widgets/CTextInput.cpp @@ -117,7 +117,7 @@ void CTextInput::setFilterNumber(int minValue, int maxValue) onTextFiltering = std::bind(&CTextInput::numberFilter, _1, _2, minValue, maxValue); } -std::string CTextInput::getVisibleText() +std::string CTextInput::getVisibleText() const { return hasFocus() ? currentText + composedText + "_" : currentText; } @@ -216,7 +216,6 @@ void CTextInput::textEdited(const std::string & enteredText) composedText = enteredText; updateLabel(); - //onTextEdited(currentText + composedText); } void CTextInput::filenameFilter(std::string & text, const std::string &oldText) diff --git a/client/widgets/CTextInput.h b/client/widgets/CTextInput.h index 72c02b1c0..a4cd7e22a 100644 --- a/client/widgets/CTextInput.h +++ b/client/widgets/CTextInput.h @@ -49,7 +49,6 @@ class CTextInput final : public CFocusable using TextEditedCallback = std::function; using TextFilterCallback = std::function; -private: std::string currentText; std::string composedText; ETextAlignment originalAlignment; @@ -66,7 +65,7 @@ private: //min-max should be set via something like std::bind static void numberFilter(std::string & text, const std::string & oldText, int minValue, int maxValue); - std::string getVisibleText(); + std::string getVisibleText() const; void createLabel(bool giveFocusToInput); void updateLabel(); diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 14626c67a..bdf99356f 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -1039,11 +1039,11 @@ void CCastleBuildings::openTownHall() void CCastleBuildings::enterAnyThievesGuild() { std::vector towns = LOCPLINT->cb->getTownsInfo(true); - for(auto & town : towns) + for(auto & ownedTown : towns) { - if(town->builtBuildings.count(BuildingID::TAVERN)) + if(ownedTown->builtBuildings.count(BuildingID::TAVERN)) { - LOCPLINT->showThievesGuildWindow(town); + LOCPLINT->showThievesGuildWindow(ownedTown); return; } } diff --git a/client/windows/CHeroWindow.cpp b/client/windows/CHeroWindow.cpp index 6078d8d30..469c3add4 100644 --- a/client/windows/CHeroWindow.cpp +++ b/client/windows/CHeroWindow.cpp @@ -208,7 +208,7 @@ void CHeroWindow::update() boost::algorithm::replace_first(helpBox, "%s", CGI->generaltexth->allTexts[43]); garr = std::make_shared(Point(15, 485), 8, Point(), curHero); - auto split = std::make_shared(Point(539, 519), AnimationPath::builtin("hsbtns9.def"), CButton::tooltip(CGI->generaltexth->allTexts[256], helpBox), [&](){ garr->splitClick(); }, EShortcut::HERO_ARMY_SPLIT); + auto split = std::make_shared(Point(539, 519), AnimationPath::builtin("hsbtns9.def"), CButton::tooltip(CGI->generaltexth->allTexts[256], helpBox), [this](){ garr->splitClick(); }, EShortcut::HERO_ARMY_SPLIT); garr->addSplitBtn(split); } if(!arts) diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index c5a07261d..e26ef4b41 100644 --- a/client/windows/GUIClasses.cpp +++ b/client/windows/GUIClasses.cpp @@ -1010,10 +1010,10 @@ CGarrisonWindow::CGarrisonWindow(const CArmedInstance * up, const CGHeroInstance garr = std::make_shared(Point(92, 127), 4, Point(0,96), up, down, removableUnits); { - auto split = std::make_shared(Point(88, 314), AnimationPath::builtin("IDV6432.DEF"), CButton::tooltip(CGI->generaltexth->tcommands[3], ""), [&](){ garr->splitClick(); }, EShortcut::HERO_ARMY_SPLIT ); + auto split = std::make_shared(Point(88, 314), AnimationPath::builtin("IDV6432.DEF"), CButton::tooltip(CGI->generaltexth->tcommands[3], ""), [this](){ garr->splitClick(); }, EShortcut::HERO_ARMY_SPLIT ); garr->addSplitBtn(split); } - quit = std::make_shared(Point(399, 314), AnimationPath::builtin("IOK6432.DEF"), CButton::tooltip(CGI->generaltexth->tcommands[8], ""), [&](){ close(); }, EShortcut::GLOBAL_ACCEPT); + quit = std::make_shared(Point(399, 314), AnimationPath::builtin("IOK6432.DEF"), CButton::tooltip(CGI->generaltexth->tcommands[8], ""), [this](){ close(); }, EShortcut::GLOBAL_ACCEPT); std::string titleText; if(down->tempOwner == up->tempOwner) diff --git a/lib/CGeneralTextHandler.cpp b/lib/CGeneralTextHandler.cpp index cea2b392f..e521b7a94 100644 --- a/lib/CGeneralTextHandler.cpp +++ b/lib/CGeneralTextHandler.cpp @@ -253,7 +253,7 @@ bool CLegacyConfigParser::endLine() void TextLocalizationContainer::registerStringOverride(const std::string & modContext, const std::string & language, const TextIdentifier & UID, const std::string & localized) { - std::lock_guard globalLock(globalTextMutex); + std::lock_guard globalLock(globalTextMutex); assert(!modContext.empty()); assert(!language.empty()); @@ -269,7 +269,7 @@ void TextLocalizationContainer::registerStringOverride(const std::string & modCo void TextLocalizationContainer::addSubContainer(const TextLocalizationContainer & container) { - std::lock_guard globalLock(globalTextMutex); + std::lock_guard globalLock(globalTextMutex); assert(!vstd::contains(subContainers, &container)); subContainers.push_back(&container); @@ -277,7 +277,7 @@ void TextLocalizationContainer::addSubContainer(const TextLocalizationContainer void TextLocalizationContainer::removeSubContainer(const TextLocalizationContainer & container) { - std::lock_guard globalLock(globalTextMutex); + std::lock_guard globalLock(globalTextMutex); assert(vstd::contains(subContainers, &container)); @@ -286,7 +286,7 @@ void TextLocalizationContainer::removeSubContainer(const TextLocalizationContain const std::string & TextLocalizationContainer::deserialize(const TextIdentifier & identifier) const { - std::lock_guard globalLock(globalTextMutex); + std::lock_guard globalLock(globalTextMutex); if(stringsLocalizations.count(identifier.get()) == 0) { @@ -307,7 +307,7 @@ const std::string & TextLocalizationContainer::deserialize(const TextIdentifier void TextLocalizationContainer::registerString(const std::string & modContext, const TextIdentifier & UID, const std::string & localized, const std::string & language) { - std::lock_guard globalLock(globalTextMutex); + std::lock_guard globalLock(globalTextMutex); assert(!modContext.empty()); assert(!Languages::getLanguageOptions(language).identifier.empty()); @@ -339,7 +339,7 @@ void TextLocalizationContainer::registerString(const std::string & modContext, c bool TextLocalizationContainer::validateTranslation(const std::string & language, const std::string & modContext, const JsonNode & config) const { - std::lock_guard globalLock(globalTextMutex); + std::lock_guard globalLock(globalTextMutex); bool allPresent = true; @@ -398,14 +398,14 @@ void TextLocalizationContainer::loadTranslationOverrides(const std::string & lan bool TextLocalizationContainer::identifierExists(const TextIdentifier & UID) const { - std::lock_guard globalLock(globalTextMutex); + std::lock_guard globalLock(globalTextMutex); return stringsLocalizations.count(UID.get()); } void TextLocalizationContainer::exportAllTexts(std::map> & storage) const { - std::lock_guard globalLock(globalTextMutex); + std::lock_guard globalLock(globalTextMutex); for (auto const & subContainer : subContainers) subContainer->exportAllTexts(storage); @@ -436,7 +436,7 @@ std::string TextLocalizationContainer::getModLanguage(const std::string & modCon void TextLocalizationContainer::jsonSerialize(JsonNode & dest) const { - std::lock_guard globalLock(globalTextMutex); + std::lock_guard globalLock(globalTextMutex); for(auto & s : stringsLocalizations) { @@ -712,7 +712,7 @@ std::string CGeneralTextHandler::getInstalledEncoding() std::vector CGeneralTextHandler::findStringsWithPrefix(const std::string & prefix) { - std::lock_guard globalLock(globalTextMutex); + std::lock_guard globalLock(globalTextMutex); std::vector result; for(const auto & entry : stringsLocalizations) diff --git a/lib/CPlayerState.h b/lib/CPlayerState.h index 516a52d0e..3c267da9d 100644 --- a/lib/CPlayerState.h +++ b/lib/CPlayerState.h @@ -140,7 +140,7 @@ public: { struct Helper : public Serializeable { - void serialize(Handler &h) + void serialize(Handler &h) const {} }; Helper helper; diff --git a/lib/CSkillHandler.cpp b/lib/CSkillHandler.cpp index 2a58f22e7..4b041368f 100644 --- a/lib/CSkillHandler.cpp +++ b/lib/CSkillHandler.cpp @@ -200,7 +200,7 @@ std::shared_ptr CSkillHandler::loadFromJson(const std::string & scope, c major = json["obligatoryMajor"].Bool(); minor = json["obligatoryMinor"].Bool(); - auto skill = std::make_shared(SecondarySkill((si32)index), identifier, major, minor); + auto skill = std::make_shared(SecondarySkill(index), identifier, major, minor); skill->modScope = scope; skill->onlyOnWaterMap = json["onlyOnWaterMap"].Bool(); diff --git a/lib/network/NetworkConnection.cpp b/lib/network/NetworkConnection.cpp index 5aa88b312..d77a1eb8c 100644 --- a/lib/network/NetworkConnection.cpp +++ b/lib/network/NetworkConnection.cpp @@ -148,7 +148,7 @@ void NetworkConnection::sendPacket(const std::vector & message) bool messageQueueEmpty = dataToSend.empty(); dataToSend.push_back(headerVector); - if (message.size() > 0) + if (!message.empty()) dataToSend.push_back(message); if (messageQueueEmpty) @@ -159,7 +159,7 @@ void NetworkConnection::sendPacket(const std::vector & message) { boost::system::error_code ec; boost::asio::write(*socket, boost::asio::buffer(headerVector), ec ); - if (message.size() > 0) + if (!message.empty()) boost::asio::write(*socket, boost::asio::buffer(message), ec ); } } diff --git a/lib/networkPacks/PacksForLobby.h b/lib/networkPacks/PacksForLobby.h index 4f189dd85..8791510d4 100644 --- a/lib/networkPacks/PacksForLobby.h +++ b/lib/networkPacks/PacksForLobby.h @@ -63,7 +63,7 @@ struct DLL_LINKAGE LobbyClientConnected : public CLobbyPackToPropagate else version = ESerializationVersion::RELEASE_150; } - catch (const std::runtime_error & e) + catch (const std::runtime_error &) { version = ESerializationVersion::RELEASE_150; } diff --git a/lib/rmg/PenroseTiling.cpp b/lib/rmg/PenroseTiling.cpp index 80395573f..8f4091cd2 100644 --- a/lib/rmg/PenroseTiling.cpp +++ b/lib/rmg/PenroseTiling.cpp @@ -181,7 +181,7 @@ std::set PenroseTiling::generatePenroseTiling(size_t numZones, CRandomG for (auto & point : points) { point = point + Point2D(0.5f, 0.5f); - }; + } // For 8XM8 map, only 650 out of 15971 points are in the range @@ -193,4 +193,4 @@ std::set PenroseTiling::generatePenroseTiling(size_t numZones, CRandomG return finalPoints; } -VCMI_LIB_NAMESPACE_END \ No newline at end of file +VCMI_LIB_NAMESPACE_END diff --git a/mapeditor/graphics.cpp b/mapeditor/graphics.cpp index 73e80b2b3..e41096556 100644 --- a/mapeditor/graphics.cpp +++ b/mapeditor/graphics.cpp @@ -124,7 +124,7 @@ void Graphics::load() void Graphics::loadHeroAnimations() { - for(auto & elem : VLC->heroclassesh->objects) + for(const auto & elem : VLC->heroclassesh->objects) { for(auto templ : VLC->objtypeh->getHandlerFor(Obj::HERO, elem->getIndex())->getTemplates()) { diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 27f8f61f6..ffaaf4784 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -985,7 +985,7 @@ ui8 CVCMIServer::getIdOfFirstUnallocatedPlayer() const void CVCMIServer::multiplayerWelcomeMessage() { int humanPlayer = 0; - for (auto & pi : si->playerInfos) + for (const auto & pi : si->playerInfos) if(pi.second.isControlledByHuman()) humanPlayer++; @@ -996,9 +996,9 @@ void CVCMIServer::multiplayerWelcomeMessage() std::vector optionIds; if(si->extraOptionsInfo.cheatsAllowed) - optionIds.push_back("vcmi.optionsTab.cheatAllowed.hover"); + optionIds.emplace_back("vcmi.optionsTab.cheatAllowed.hover"); if(si->extraOptionsInfo.unlimitedReplay) - optionIds.push_back("vcmi.optionsTab.unlimitedReplay.hover"); + optionIds.emplace_back("vcmi.optionsTab.unlimitedReplay.hover"); if(!optionIds.size()) // No settings to publish return;