1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-27 12:22:45 +02:00

Fixed new issues detected by SonarCloud

This commit is contained in:
Ivan Savenko 2024-07-15 07:46:40 +00:00
parent 6b8f94e6e7
commit c00a1e1b0c
8 changed files with 24 additions and 40 deletions

@ -1125,7 +1125,7 @@ void CPlayerInterface::showMapObjectSelectDialog(QueryID askID, const Component
std::vector<int> tempList; std::vector<int> tempList;
tempList.reserve(objectGuiOrdered.size()); tempList.reserve(objectGuiOrdered.size());
for(auto item : objectGuiOrdered) for(const auto & item : objectGuiOrdered)
tempList.push_back(item.getNum()); tempList.push_back(item.getNum());
CComponent localIconC(icon); CComponent localIconC(icon);
@ -1134,7 +1134,7 @@ void CPlayerInterface::showMapObjectSelectDialog(QueryID askID, const Component
localIconC.removeChild(localIcon.get(), false); localIconC.removeChild(localIcon.get(), false);
std::vector<std::shared_ptr<IImage>> images; std::vector<std::shared_ptr<IImage>> images;
for(auto & obj : objectGuiOrdered) for(const auto & obj : objectGuiOrdered)
{ {
if(!settings["general"]["enableUiEnhancements"].Bool()) if(!settings["general"]["enableUiEnhancements"].Bool())
break; break;

@ -368,8 +368,8 @@ void FirstLaunchView::extractGogData()
QString errorText{}; QString errorText{};
auto isGogGalaxyExe = [](QString fileExe) { auto isGogGalaxyExe = [](QString fileToTest) {
QFile file(fileExe); QFile file(fileToTest);
quint64 fileSize = file.size(); quint64 fileSize = file.size();
if(fileSize > 10 * 1024 * 1024) if(fileSize > 10 * 1024 * 1024)
@ -379,7 +379,7 @@ void FirstLaunchView::extractGogData()
return false; return false;
QByteArray data = file.readAll(); 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); return data.contains(magicId);
}; };

@ -27,9 +27,7 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#endif #endif
namespace static QString resolutionToString(const QSize & resolution)
{
QString resolutionToString(const QSize & resolution)
{ {
return QString{"%1x%2"}.arg(resolution.width()).arg(resolution.height()); return QString{"%1x%2"}.arg(resolution.width()).arg(resolution.height());
} }
@ -47,8 +45,6 @@ static constexpr std::array upscalingFilterTypes =
"best" "best"
}; };
}
void CSettingsView::setDisplayList() void CSettingsView::setDisplayList()
{ {
QStringList list; QStringList list;

@ -138,11 +138,11 @@ static void createMemoryDump(MINIDUMP_EXCEPTION_INFORMATION * meinfo)
| MiniDumpWithThreadInfo); | 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); 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."); logGlobal->error("Disaster happened.");
try try

@ -99,7 +99,7 @@ int BonusList::totalValue() const
int indepMax = std::numeric_limits<int>::min(); 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; return (static_cast<int64_t>(base) * (100 + percent)) / 100;
}; };
@ -125,7 +125,7 @@ int BonusList::totalValue() const
for(const auto & b : bonuses) for(const auto & b : bonuses)
{ {
int sourceIndex = vstd::to_underlying(b->source); int sourceIndex = vstd::to_underlying(b->source);
int valModified = percent(b->val, percentToSource[sourceIndex]); int valModified = applyPercentage(b->val, percentToSource[sourceIndex]);
switch(b->valType) 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; 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) if(hasIndepMin && hasIndepMax && accumulated.indepMin < accumulated.indepMax)
accumulated.indepMax = accumulated.indepMin; accumulated.indepMax = accumulated.indepMin;
@ -167,7 +167,13 @@ int BonusList::totalValue() const
if(notIndepBonuses) if(notIndepBonuses)
return std::clamp(valFirst, accumulated.indepMax, accumulated.indepMin); 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) std::shared_ptr<Bonus> BonusList::getFirst(const CSelector &select)

@ -101,10 +101,10 @@ void CCastleEvent::serializeJson(JsonSerializeFormat & handler)
TerrainTile::TerrainTile(): TerrainTile::TerrainTile():
terType(nullptr), terType(nullptr),
terView(0),
riverType(VLC->riverTypeHandler->getById(River::NO_RIVER)), riverType(VLC->riverTypeHandler->getById(River::NO_RIVER)),
riverDir(0),
roadType(VLC->roadTypeHandler->getById(Road::NO_ROAD)), roadType(VLC->roadTypeHandler->getById(Road::NO_ROAD)),
terView(0),
riverDir(0),
roadDir(0), roadDir(0),
extTileFlags(0), extTileFlags(0),
visitable(false), visitable(false),

@ -37,10 +37,10 @@ public:
class CBattleDialogQuery : public CDialogQuery class CBattleDialogQuery : public CDialogQuery
{ {
bool resultProcessed = false; bool resultProcessed = false;
public:
CBattleDialogQuery(CGameHandler * owner, const IBattleInfo * Bi, std::optional<BattleResult> Br);
const IBattleInfo * bi; const IBattleInfo * bi;
std::optional<BattleResult> result; std::optional<BattleResult> result;
public:
CBattleDialogQuery(CGameHandler * owner, const IBattleInfo * Bi, std::optional<BattleResult> Br);
void onRemoval(PlayerColor color) override; void onRemoval(PlayerColor color) override;
}; };

@ -17,24 +17,6 @@
#include "../../lib/serializer/Cast.h" #include "../../lib/serializer/Cast.h"
#include "../../lib/networkPacks/PacksForServer.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) std::ostream & operator<<(std::ostream & out, const CQuery & query)
{ {
return out << query.toString(); return out << query.toString();