Browse Source

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

Fix Clang Analyzer warnings
Andrii Danylchenko 3 years ago
parent
commit
878aabd4d6

+ 3 - 0
AI/Nullkiller/AIUtility.cpp

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

+ 0 - 4
AI/Nullkiller/Analyzers/BuildAnalyzer.cpp

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

+ 1 - 0
AI/Nullkiller/Behaviors/CaptureObjectsBehavior.cpp

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

+ 0 - 1
AI/Nullkiller/Pathfinding/Rules/AIMovementAfterDestinationRule.cpp

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

+ 1 - 0
client/CMessage.cpp

@@ -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}};
 	const int sizes[][2] = {{400, 125}, {500, 150}, {600, 200}, {480, 400}};
 
 
+	assert(ret && ret->text);
 	for(int i = 0;
 	for(int i = 0;
 		i < ARRAY_COUNT(sizes)
 		i < ARRAY_COUNT(sizes)
 			&& sizes[i][0] < screen->w - 150
 			&& sizes[i][0] < screen->w - 150

+ 1 - 1
client/CPlayerInterface.cpp

@@ -1327,7 +1327,7 @@ void CPlayerInterface::availableCreaturesChanged( const CGDwelling *town )
 				ki->townChanged(townObj);
 				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))
 		||  town->ID == Obj::CREATURE_GENERATOR4  ||  town->ID == Obj::WAR_MACHINE_FACTORY))
 	{
 	{
 		CRecruitmentWindow *crw = dynamic_cast<CRecruitmentWindow*>(GH.topInt().get());
 		CRecruitmentWindow *crw = dynamic_cast<CRecruitmentWindow*>(GH.topInt().get());

+ 1 - 1
client/battle/CBattleAnimations.cpp

@@ -196,7 +196,7 @@ bool CDefenceAnimation::init()
 	}
 	}
 	//unit reversed
 	//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)
 		for(std::list<ProjectileInfo>::const_iterator it = owner->projectiles.begin(); it != owner->projectiles.end(); ++it)
 		{
 		{

+ 3 - 0
client/windows/CKingdomInterface.cpp

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

+ 1 - 1
lib/CCreatureHandler.cpp

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

+ 1 - 1
lib/CPathfinder.cpp

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

+ 1 - 0
lib/CStack.cpp

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

+ 2 - 4
lib/NetPacksLib.cpp

@@ -918,10 +918,8 @@ DLL_LINKAGE void SwapStacks::applyGs(CGameState * gs)
 
 
 DLL_LINKAGE void InsertNewStack::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
 	else
 		logNetwork->error("[CRITICAL] InsertNewStack: invalid army object %d, possible game state corruption.", army.getNum());
 		logNetwork->error("[CRITICAL] InsertNewStack: invalid army object %d, possible game state corruption.", army.getNum());
 }
 }

+ 1 - 0
lib/spells/ISpellMechanics.cpp

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