1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

Merge pull request #981 from kambala-decapitator/fix-analyzer-warnings

Fix Clang Analyzer warnings
This commit is contained in:
Andrii Danylchenko 2022-09-29 19:23:24 +03:00 committed by GitHub
commit 878aabd4d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 16 additions and 13 deletions

View File

@ -307,6 +307,9 @@ bool compareArtifacts(const CArtifactInstance * a1, const CArtifactInstance * a2
bool isWeeklyRevisitable(const CGObjectInstance * obj)
{
if(!obj)
return false;
//TODO: allow polling of remaining creatures in dwelling
if(dynamic_cast<const CGVisitableOPW *>(obj)) // ensures future compatibility, unlike IDs
return true;

View File

@ -205,8 +205,6 @@ BuildingInfo BuildAnalyzer::getBuildingOrPrerequisite(
logAi->trace("checking %s", info.name);
logAi->trace("buildInfo %s", info.toString());
buildPtr = nullptr;
if(!town->hasBuilt(building))
{
auto canBuild = ai->cb->canBuildStructure(town, building);
@ -239,8 +237,6 @@ BuildingInfo BuildAnalyzer::getBuildingOrPrerequisite(
}
else
{
buildPtr = townInfo->buildings.at(building);
logAi->trace("cant build. Need %d", missingBuildings[0].num);
BuildingInfo prerequisite = getBuildingOrPrerequisite(town, missingBuildings[0], excludeDwellingDependencies);

View File

@ -133,6 +133,7 @@ Goals::TGoalVec CaptureObjectsBehavior::getVisitGoals(const std::vector<AIPath>
}
}
assert(closestWay || waysToVisitObj.empty());
for(auto way : waysToVisitObj)
{
way->closestWayRatio

View File

@ -147,7 +147,6 @@ namespace AIPathfinding
return false;
}
destinationNode = questNode.get();
destination.node = questNode.get();
nodeStorage->commit(destination, source);

View File

@ -208,6 +208,7 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, PlayerColor play
const int sizes[][2] = {{400, 125}, {500, 150}, {600, 200}, {480, 400}};
assert(ret && ret->text);
for(int i = 0;
i < ARRAY_COUNT(sizes)
&& sizes[i][0] < screen->w - 150

View File

@ -1327,7 +1327,7 @@ void CPlayerInterface::availableCreaturesChanged( const CGDwelling *town )
ki->townChanged(townObj);
}
}
else if (GH.listInt.size() && (town->ID == Obj::CREATURE_GENERATOR1
else if(town && GH.listInt.size() && (town->ID == Obj::CREATURE_GENERATOR1
|| town->ID == Obj::CREATURE_GENERATOR4 || town->ID == Obj::WAR_MACHINE_FACTORY))
{
CRecruitmentWindow *crw = dynamic_cast<CRecruitmentWindow*>(GH.topInt().get());

View File

@ -196,7 +196,7 @@ bool CDefenceAnimation::init()
}
//unit reversed
if(rangedAttack) //delay hit animation
if(rangedAttack && attacker != nullptr) //delay hit animation
{
for(std::list<ProjectileInfo>::const_iterator it = owner->projectiles.begin(); it != owner->projectiles.end(); ++it)
{

View File

@ -315,6 +315,9 @@ int InfoBoxHeroData::getSubID()
si64 InfoBoxHeroData::getValue()
{
if(!hero)
return 0;
switch(type)
{
case HERO_PRIMARY_SKILL:

View File

@ -1232,7 +1232,7 @@ void CCreatureHandler::loadStackExp(Bonus & b, BonusList & bl, CLegacyConfigPars
{
if (b.type != Bonus::REBIRTH)
b.val = 0; //on-off ability, no value specified
curVal = static_cast<si32>(parser.readNumber());// 0 level is never active
parser.readNumber(); // 0 level is never active
for (int i = 1; i < 11; ++i)
{
curVal = static_cast<si32>(parser.readNumber());

View File

@ -465,7 +465,7 @@ std::vector<int3> CPathfinderHelper::getAllowedTeleportChannelExits(TeleportChan
allowedExits.push_back(p);
}
}
else if(CGTeleport::isExitPassable(gs, hero, obj))
else if(obj && CGTeleport::isExitPassable(gs, hero, obj))
allowedExits.push_back(obj->visitablePos());
}

View File

@ -306,6 +306,7 @@ std::vector<BattleHex> CStack::meleeAttackHexes(const battle::Unit * attacker, c
res.push_back(otherDefenderPos);
}
}
UNUSED(mask);
return res;
}

View File

@ -918,10 +918,8 @@ DLL_LINKAGE void SwapStacks::applyGs(CGameState * gs)
DLL_LINKAGE void InsertNewStack::applyGs(CGameState *gs)
{
auto s = new CStackInstance(type, count);
auto obj = gs->getArmyInstance(army);
if(obj)
obj->putStack(slot, s);
if(auto obj = gs->getArmyInstance(army))
obj->putStack(slot, new CStackInstance(type, count));
else
logNetwork->error("[CRITICAL] InsertNewStack: invalid army object %d, possible game state corruption.", army.getNum());
}

View File

@ -492,6 +492,7 @@ bool BaseMechanics::adaptGenericProblem(Problem & target) const
MetaString text;
// %s recites the incantations but they seem to have no effect.
text.addTxt(MetaString::GENERAL_TXT, 541);
assert(caster);
caster->getCasterName(text);
target.add(std::move(text), spells::Problem::NORMAL);