From c00a1e1b0ce5821c3f9b8b49b046033412d35802 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Mon, 15 Jul 2024 07:46:40 +0000 Subject: [PATCH] Fixed new issues detected by SonarCloud --- client/CPlayerInterface.cpp | 4 ++-- launcher/firstLaunch/firstlaunch_moc.cpp | 6 +++--- launcher/settingsView/csettingsview_moc.cpp | 6 +----- lib/CConsoleHandler.cpp | 4 ++-- lib/bonuses/BonusList.cpp | 16 +++++++++++----- lib/mapping/CMap.cpp | 4 ++-- server/queries/BattleQueries.h | 6 +++--- server/queries/CQuery.cpp | 18 ------------------ 8 files changed, 24 insertions(+), 40 deletions(-) diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 4c9e79447..db2f7ab0f 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -1125,7 +1125,7 @@ void CPlayerInterface::showMapObjectSelectDialog(QueryID askID, const Component std::vector tempList; tempList.reserve(objectGuiOrdered.size()); - for(auto item : objectGuiOrdered) + for(const auto & item : objectGuiOrdered) tempList.push_back(item.getNum()); CComponent localIconC(icon); @@ -1134,7 +1134,7 @@ void CPlayerInterface::showMapObjectSelectDialog(QueryID askID, const Component localIconC.removeChild(localIcon.get(), false); std::vector> images; - for(auto & obj : objectGuiOrdered) + for(const auto & obj : objectGuiOrdered) { if(!settings["general"]["enableUiEnhancements"].Bool()) break; diff --git a/launcher/firstLaunch/firstlaunch_moc.cpp b/launcher/firstLaunch/firstlaunch_moc.cpp index 78ecf7a20..98671a681 100644 --- a/launcher/firstLaunch/firstlaunch_moc.cpp +++ b/launcher/firstLaunch/firstlaunch_moc.cpp @@ -368,8 +368,8 @@ void FirstLaunchView::extractGogData() QString errorText{}; - auto isGogGalaxyExe = [](QString fileExe) { - QFile file(fileExe); + auto isGogGalaxyExe = [](QString fileToTest) { + QFile file(fileToTest); quint64 fileSize = file.size(); if(fileSize > 10 * 1024 * 1024) @@ -379,7 +379,7 @@ void FirstLaunchView::extractGogData() return false; QByteArray data = file.readAll(); - const QByteArray magicId{(const char*)u"GOG Galaxy", 20}; + const QByteArray magicId{reinterpret_cast(u"GOG Galaxy"), 20}; return data.contains(magicId); }; diff --git a/launcher/settingsView/csettingsview_moc.cpp b/launcher/settingsView/csettingsview_moc.cpp index 2e7642553..85f352537 100644 --- a/launcher/settingsView/csettingsview_moc.cpp +++ b/launcher/settingsView/csettingsview_moc.cpp @@ -27,9 +27,7 @@ #include #endif -namespace -{ -QString resolutionToString(const QSize & resolution) +static QString resolutionToString(const QSize & resolution) { return QString{"%1x%2"}.arg(resolution.width()).arg(resolution.height()); } @@ -47,8 +45,6 @@ static constexpr std::array upscalingFilterTypes = "best" }; -} - void CSettingsView::setDisplayList() { QStringList list; diff --git a/lib/CConsoleHandler.cpp b/lib/CConsoleHandler.cpp index 6d2fc3640..05ea6f428 100644 --- a/lib/CConsoleHandler.cpp +++ b/lib/CConsoleHandler.cpp @@ -138,11 +138,11 @@ static void createMemoryDump(MINIDUMP_EXCEPTION_INFORMATION * meinfo) | MiniDumpWithThreadInfo); } - MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), dfile, dumpType, meinfo, 0, 0); + MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), dfile, dumpType, meinfo, nullptr, nullptr); MessageBoxA(0, "VCMI has crashed. We are sorry. File with information about encountered problem has been created.", "VCMI Crashhandler", MB_OK | MB_ICONERROR); } -static void onTerminate() +[[noreturn]] static void onTerminate() { logGlobal->error("Disaster happened."); try diff --git a/lib/bonuses/BonusList.cpp b/lib/bonuses/BonusList.cpp index c3e645ac3..c7e5deb57 100644 --- a/lib/bonuses/BonusList.cpp +++ b/lib/bonuses/BonusList.cpp @@ -99,7 +99,7 @@ int BonusList::totalValue() const int indepMax = std::numeric_limits::min(); }; - auto percent = [](int base, int percent) -> int { + auto applyPercentage = [](int base, int percent) -> int { return (static_cast(base) * (100 + percent)) / 100; }; @@ -125,7 +125,7 @@ int BonusList::totalValue() const for(const auto & b : bonuses) { int sourceIndex = vstd::to_underlying(b->source); - int valModified = percent(b->val, percentToSource[sourceIndex]); + int valModified = applyPercentage(b->val, percentToSource[sourceIndex]); switch(b->valType) { @@ -152,9 +152,9 @@ int BonusList::totalValue() const } } - accumulated.base = percent(accumulated.base, accumulated.percentToBase); + accumulated.base = applyPercentage(accumulated.base, accumulated.percentToBase); accumulated.base += accumulated.additive; - auto valFirst = percent(accumulated.base ,accumulated.percentToAll); + auto valFirst = applyPercentage(accumulated.base ,accumulated.percentToAll); if(hasIndepMin && hasIndepMax && accumulated.indepMin < accumulated.indepMax) accumulated.indepMax = accumulated.indepMin; @@ -167,7 +167,13 @@ int BonusList::totalValue() const if(notIndepBonuses) return std::clamp(valFirst, accumulated.indepMax, accumulated.indepMin); - return hasIndepMin ? accumulated.indepMin : hasIndepMax ? accumulated.indepMax : 0; + if (hasIndepMin) + return accumulated.indepMin; + + if (hasIndepMax) + return accumulated.indepMax; + + return 0; } std::shared_ptr BonusList::getFirst(const CSelector &select) diff --git a/lib/mapping/CMap.cpp b/lib/mapping/CMap.cpp index ad2bf657a..cb0f5dbf1 100644 --- a/lib/mapping/CMap.cpp +++ b/lib/mapping/CMap.cpp @@ -101,10 +101,10 @@ void CCastleEvent::serializeJson(JsonSerializeFormat & handler) TerrainTile::TerrainTile(): terType(nullptr), - terView(0), riverType(VLC->riverTypeHandler->getById(River::NO_RIVER)), - riverDir(0), roadType(VLC->roadTypeHandler->getById(Road::NO_ROAD)), + terView(0), + riverDir(0), roadDir(0), extTileFlags(0), visitable(false), diff --git a/server/queries/BattleQueries.h b/server/queries/BattleQueries.h index 07b6d7b56..cae8c3b09 100644 --- a/server/queries/BattleQueries.h +++ b/server/queries/BattleQueries.h @@ -37,10 +37,10 @@ public: class CBattleDialogQuery : public CDialogQuery { bool resultProcessed = false; -public: - CBattleDialogQuery(CGameHandler * owner, const IBattleInfo * Bi, std::optional Br); - const IBattleInfo * bi; std::optional result; + +public: + CBattleDialogQuery(CGameHandler * owner, const IBattleInfo * Bi, std::optional Br); void onRemoval(PlayerColor color) override; }; diff --git a/server/queries/CQuery.cpp b/server/queries/CQuery.cpp index 7e18b7ec9..02eb14762 100644 --- a/server/queries/CQuery.cpp +++ b/server/queries/CQuery.cpp @@ -17,24 +17,6 @@ #include "../../lib/serializer/Cast.h" #include "../../lib/networkPacks/PacksForServer.h" -template -std::string formatContainer(const Container & c, std::string delimiter = ", ", std::string opener = "(", std::string closer=")") -{ - std::string ret = opener; - auto itr = std::begin(c); - if(itr != std::end(c)) - { - ret += std::to_string(*itr); - while(++itr != std::end(c)) - { - ret += delimiter; - ret += std::to_string(*itr); - } - } - ret += closer; - return ret; -} - std::ostream & operator<<(std::ostream & out, const CQuery & query) { return out << query.toString();