Quellcode durchsuchen

Fixed new issues detected by SonarCloud

Ivan Savenko vor 1 Jahr
Ursprung
Commit
c00a1e1b0c

+ 2 - 2
client/CPlayerInterface.cpp

@@ -1125,7 +1125,7 @@ void CPlayerInterface::showMapObjectSelectDialog(QueryID askID, const Component
 	std::vector<int> 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<std::shared_ptr<IImage>> images;
-	for(auto & obj : objectGuiOrdered)
+	for(const auto & obj : objectGuiOrdered)
 	{
 		if(!settings["general"]["enableUiEnhancements"].Bool())
 			break;

+ 3 - 3
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<const char*>(u"GOG Galaxy"), 20};
 			return data.contains(magicId);
 		};
 

+ 1 - 5
launcher/settingsView/csettingsview_moc.cpp

@@ -27,9 +27,7 @@
 #include <SDL2/SDL.h>
 #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;

+ 2 - 2
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

+ 11 - 5
lib/bonuses/BonusList.cpp

@@ -99,7 +99,7 @@ int BonusList::totalValue() const
 		int indepMax = std::numeric_limits<int>::min();
 	};
 
-	auto percent = [](int base, int percent) -> int {
+	auto applyPercentage = [](int base, int percent) -> int {
 		return (static_cast<int64_t>(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<Bonus> BonusList::getFirst(const CSelector &select)

+ 2 - 2
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),

+ 3 - 3
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<BattleResult> Br);
-
 	const IBattleInfo * bi;
 	std::optional<BattleResult> result;
+
+public:
+	CBattleDialogQuery(CGameHandler * owner, const IBattleInfo * Bi, std::optional<BattleResult> Br);
 	void onRemoval(PlayerColor color) override;
 };

+ 0 - 18
server/queries/CQuery.cpp

@@ -17,24 +17,6 @@
 #include "../../lib/serializer/Cast.h"
 #include "../../lib/networkPacks/PacksForServer.h"
 
-template <typename Container>
-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();