Core/Misc: Fix static analysis issues (#25194)

(cherry picked from commit 07fd84b679fd6958b7e669a96c78783875e1b949)
This commit is contained in:
Giacomo Pozzoni
2022-01-26 14:06:40 +01:00
committed by Shauren
parent afcb13cd44
commit 864d775280
18 changed files with 35 additions and 39 deletions
@@ -67,9 +67,7 @@ SmartScript::~SmartScript()
{ {
} }
// @todo this is an utter clusterfuck in terms of design - why in the world does this thing side effect? bool SmartScript::IsSmart(Creature* c, bool silent) const
// seriously, WHO WRITES THIS SHIT
bool SmartScript::IsSmart(Creature* c, bool silent)
{ {
if (!c) if (!c)
return false; return false;
@@ -79,13 +77,12 @@ bool SmartScript::IsSmart(Creature* c, bool silent)
smart = false; smart = false;
if (!smart && !silent) if (!smart && !silent)
TC_LOG_ERROR("sql.sql", "SmartScript: Action target Creature (GUID: " UI64FMTD " Entry: %u) is not using SmartAI, action called by Creature (GUID: " UI64FMTD " Entry: %u) skipped to prevent crash.", uint64(c ? c->GetSpawnId() : UI64LIT(0)), c ? c->GetEntry() : 0, uint64(me ? me->GetSpawnId() : UI64LIT(0)), me ? me->GetEntry() : 0); TC_LOG_ERROR("sql.sql", "SmartScript: Action target Creature (GUID: " UI64FMTD " Entry: %u) is not using SmartAI, action called by Creature (GUID: " UI64FMTD " Entry: %u) skipped to prevent crash.", c->GetSpawnId(), c->GetEntry(), uint64(me ? me->GetSpawnId() : UI64LIT(0)), me ? me->GetEntry() : 0);
return smart; return smart;
} }
// @todo this, too bool SmartScript::IsSmart(GameObject* g, bool silent) const
bool SmartScript::IsSmart(GameObject* g, bool silent)
{ {
if (!g) if (!g)
return false; return false;
@@ -95,12 +92,12 @@ bool SmartScript::IsSmart(GameObject* g, bool silent)
smart = false; smart = false;
if (!smart && !silent) if (!smart && !silent)
TC_LOG_ERROR("sql.sql", "SmartScript: Action target GameObject (GUID: " UI64FMTD " Entry: %u) is not using SmartGameObjectAI, action called by GameObject (GUID: " UI64FMTD " Entry: %u) skipped to prevent crash.", uint64(g ? g->GetSpawnId() : UI64LIT(0)), g ? g->GetEntry() : 0, uint64(go ? go->GetSpawnId() : UI64LIT(0)), go ? go->GetEntry() : 0); TC_LOG_ERROR("sql.sql", "SmartScript: Action target GameObject (GUID: " UI64FMTD " Entry: %u) is not using SmartGameObjectAI, action called by GameObject (GUID: " UI64FMTD " Entry: %u) skipped to prevent crash.", g->GetSpawnId(), g->GetEntry(), uint64(go ? go->GetSpawnId() : UI64LIT(0)), go ? go->GetEntry() : 0);
return smart; return smart;
} }
bool SmartScript::IsSmart(bool silent) bool SmartScript::IsSmart(bool silent) const
{ {
if (me) if (me)
return IsSmart(me, silent); return IsSmart(me, silent);
@@ -74,9 +74,9 @@ class TC_GAME_API SmartScript
void DoFindFriendlyMissingBuff(std::vector<Creature*>& creatures, float range, uint32 spellid) const; void DoFindFriendlyMissingBuff(std::vector<Creature*>& creatures, float range, uint32 spellid) const;
Unit* DoFindClosestFriendlyInRange(float range, bool playerOnly) const; Unit* DoFindClosestFriendlyInRange(float range, bool playerOnly) const;
bool IsSmart(Creature* c, bool silent = false); bool IsSmart(Creature* c, bool silent = false) const;
bool IsSmart(GameObject* g, bool silent = false); bool IsSmart(GameObject* g, bool silent = false) const;
bool IsSmart(bool silent = false); bool IsSmart(bool silent = false) const;
void StoreTargetList(ObjectVector const& targets, uint32 id); void StoreTargetList(ObjectVector const& targets, uint32 id);
void AddToStoredTargetList(ObjectVector const& targets, uint32 id); void AddToStoredTargetList(ObjectVector const& targets, uint32 id);
@@ -2013,7 +2013,7 @@ bool Creature::CanStartAttack(Unit const* who, bool force) const
if (!_IsTargetAcceptable(who)) if (!_IsTargetAcceptable(who))
return false; return false;
if (!force && (IsNeutralToAll() || !IsWithinDistInMap(who, GetAttackDistance(who) + m_CombatDistance))) if (IsNeutralToAll() || !IsWithinDistInMap(who, GetAttackDistance(who) + m_CombatDistance))
return false; return false;
} }
+1 -1
View File
@@ -2999,7 +2999,7 @@ bool WorldObject::IsValidAssistTarget(WorldObject const* target, SpellInfo const
// can't assist player out of sanctuary from sanctuary if has pvp enabled // can't assist player out of sanctuary from sanctuary if has pvp enabled
if (unitTarget->IsPvP()) if (unitTarget->IsPvP())
if (unit && unit->IsInSanctuary() && !unitTarget->IsInSanctuary()) if (unit->IsInSanctuary() && !unitTarget->IsInSanctuary())
return false; return false;
} }
} }
+1 -1
View File
@@ -21882,7 +21882,7 @@ void Player::UpdatePvPFlag(time_t currTime)
if (!pvpInfo.EndTimer || (currTime < pvpInfo.EndTimer +300) || pvpInfo.IsHostile) if (!pvpInfo.EndTimer || (currTime < pvpInfo.EndTimer +300) || pvpInfo.IsHostile)
return; return;
if (pvpInfo.EndTimer && pvpInfo.EndTimer <= currTime) if (pvpInfo.EndTimer <= currTime)
{ {
pvpInfo.EndTimer = 0; pvpInfo.EndTimer = 0;
RemovePlayerFlag(PLAYER_FLAGS_PVP_TIMER); RemovePlayerFlag(PLAYER_FLAGS_PVP_TIMER);
+1 -1
View File
@@ -11111,7 +11111,7 @@ void Unit::RemoveCharmedBy(Unit* charmer)
CharmType type; CharmType type;
if (HasUnitState(UNIT_STATE_POSSESSED)) if (HasUnitState(UNIT_STATE_POSSESSED))
type = CHARM_TYPE_POSSESS; type = CHARM_TYPE_POSSESS;
else if (charmer && charmer->IsOnVehicle(this)) else if (charmer->IsOnVehicle(this))
type = CHARM_TYPE_VEHICLE; type = CHARM_TYPE_VEHICLE;
else else
type = CHARM_TYPE_CHARM; type = CHARM_TYPE_CHARM;
+2 -2
View File
@@ -930,7 +930,7 @@ void WorldSession::HandleSetDungeonDifficultyOpcode(WorldPackets::Misc::SetDunge
if (!groupGuy) if (!groupGuy)
continue; continue;
if (!groupGuy->IsInMap(groupGuy)) if (!groupGuy->IsInWorld())
return; return;
if (groupGuy->GetMap()->IsNonRaidDungeon()) if (groupGuy->GetMap()->IsNonRaidDungeon())
@@ -1009,7 +1009,7 @@ void WorldSession::HandleSetRaidDifficultyOpcode(WorldPackets::Misc::SetRaidDiff
if (!groupGuy) if (!groupGuy)
continue; continue;
if (!groupGuy->IsInMap(groupGuy)) if (!groupGuy->IsInWorld())
return; return;
if (groupGuy->GetMap()->IsRaid()) if (groupGuy->GetMap()->IsRaid())
+1 -1
View File
@@ -4343,7 +4343,7 @@ void SpellMgr::LoadSpellInfoCorrections()
// Val'kyr Target Search // Val'kyr Target Search
ApplySpellFix({ 69030 }, [](SpellInfo* spellInfo) ApplySpellFix({ 69030 }, [](SpellInfo* spellInfo)
{ {
spellInfo->Attributes |= SPELL_ATTR0_UNAFFECTED_BY_INVULNERABILITY; spellInfo->Attributes |= SPELL_ATTR0_UNAFFECTED_BY_INVULNERABILITY;
}); });
// Raging Spirit Visual // Raging Spirit Visual
+1 -1
View File
@@ -145,7 +145,7 @@ public:
handler->SendSysMessage("========================"); handler->SendSysMessage("========================");
} }
std::string const& name = itr->second->GetName(); std::string const& name = itr->second->GetName();
uint8 size = name.size(); uint8 size = uint8(name.size());
uint8 security = itrSec; uint8 security = itrSec;
uint8 max = ((16 - size) / 2); uint8 max = ((16 - size) / 2);
uint8 max2 = max; uint8 max2 = max;
+3 -3
View File
@@ -248,7 +248,7 @@ public:
if (count > resultCount) if (count > resultCount)
count -= resultCount; count -= resultCount;
else if (count) else
count = 0; count = 0;
} }
@@ -295,7 +295,7 @@ public:
if (count > resultCount) if (count > resultCount)
count -= resultCount; count -= resultCount;
else if (count) else
count = 0; count = 0;
} }
@@ -370,7 +370,7 @@ public:
if (count > resultCount) if (count > resultCount)
count -= resultCount; count -= resultCount;
else if (count) else
count = 0; count = 0;
} }
+1 -1
View File
@@ -1569,7 +1569,7 @@ public:
// the max level of the new profession. // the max level of the new profession.
uint16 max = maxPureSkill ? atoul(maxPureSkill) : targetHasSkill ? target->GetPureMaxSkillValue(skill) : uint16(level); uint16 max = maxPureSkill ? atoul(maxPureSkill) : targetHasSkill ? target->GetPureMaxSkillValue(skill) : uint16(level);
if (level == 0 || level > max || max <= 0) if (level == 0 || level > max)
return false; return false;
// If the player has the skill, we get the current skill step. If they don't have the skill, we // If the player has the skill, we get the current skill step. If they don't have the skill, we
@@ -325,7 +325,6 @@ public:
if (RaidWiped) if (RaidWiped)
{ {
RaidWiped = true;
EnterEvadeMode(); EnterEvadeMode();
return; return;
} }
@@ -305,7 +305,7 @@ struct npc_head : public ScriptedAI
ReturnToBody(true); ReturnToBody(true);
break; break;
case PHASE_HEAD_3: case PHASE_HEAD_3:
if (!_die && damage >= me->GetHealth()) if (damage >= me->GetHealth())
{ {
_die = true; _die = true;
damage = 0; damage = 0;
@@ -234,7 +234,7 @@ class spell_koralon_meteor_fists_damage : public SpellScriptLoader
private: private:
void FilterTargets(std::list<WorldObject*>& targets) void FilterTargets(std::list<WorldObject*>& targets)
{ {
_chainTargets = targets.size(); _chainTargets = uint8(targets.size());
} }
void CalculateSplitDamage() void CalculateSplitDamage()
@@ -686,8 +686,7 @@ public:
while (unit == nullptr || !unit->IsAlive()) while (unit == nullptr || !unit->IsAlive())
unit = selectAdvisorUnit(); unit = selectAdvisorUnit();
if (unit && unit->IsAlive()) DoCast(unit, SPELL_HEAL);
DoCast(unit, SPELL_HEAL);
Heal_Timer = 60000; Heal_Timer = 60000;
} }
else else
@@ -222,7 +222,7 @@ public:
{ {
//Teleport 4 players under the waterfalls //Teleport 4 players under the waterfalls
GuidSet targets; GuidSet targets;
GuidSet::const_iterator itr; GuidSet::const_iterator itr = targets.begin();
for (uint8 i = 0; i < 4; ++i) for (uint8 i = 0; i < 4; ++i)
{ {
counter = 0; counter = 0;
@@ -260,7 +260,7 @@ public:
if (WateryGlobules_Timer <= diff) if (WateryGlobules_Timer <= diff)
{ {
GuidSet globules; GuidSet globules;
GuidSet::const_iterator itr; GuidSet::const_iterator itr = globules.begin();
for (uint8 g = 0; g < 4; g++) //one unit can't cast more than one spell per update, so some players have to cast for us XD for (uint8 g = 0; g < 4; g++) //one unit can't cast more than one spell per update, so some players have to cast for us XD
{ {
counter = 0; counter = 0;
@@ -274,6 +274,7 @@ public:
break; break;
++counter; ++counter;
} while (itr != globules.end()); } while (itr != globules.end());
if (pGlobuleTarget) if (pGlobuleTarget)
{ {
globules.insert(pGlobuleTarget->GetGUID()); globules.insert(pGlobuleTarget->GetGUID());
@@ -190,19 +190,19 @@ class instance_blood_furnace : public InstanceMapScript
void ResetPrisons() void ResetPrisons()
{ {
ResetPrisoners(PrisonersCell5); ResetPrisoners(PrisonersCell5);
PrisonerCounter5 = PrisonersCell5.size(); PrisonerCounter5 = uint8(PrisonersCell5.size());
HandleGameObject(PrisonCellGUIDs[DATA_PRISON_CELL5 - DATA_PRISON_CELL1], false); HandleGameObject(PrisonCellGUIDs[DATA_PRISON_CELL5 - DATA_PRISON_CELL1], false);
ResetPrisoners(PrisonersCell6); ResetPrisoners(PrisonersCell6);
PrisonerCounter6 = PrisonersCell6.size(); PrisonerCounter6 = uint8(PrisonersCell6.size());
HandleGameObject(PrisonCellGUIDs[DATA_PRISON_CELL6 - DATA_PRISON_CELL1], false); HandleGameObject(PrisonCellGUIDs[DATA_PRISON_CELL6 - DATA_PRISON_CELL1], false);
ResetPrisoners(PrisonersCell7); ResetPrisoners(PrisonersCell7);
PrisonerCounter7 = PrisonersCell7.size(); PrisonerCounter7 = uint8(PrisonersCell7.size());
HandleGameObject(PrisonCellGUIDs[DATA_PRISON_CELL7 - DATA_PRISON_CELL1], false); HandleGameObject(PrisonCellGUIDs[DATA_PRISON_CELL7 - DATA_PRISON_CELL1], false);
ResetPrisoners(PrisonersCell8); ResetPrisoners(PrisonersCell8);
PrisonerCounter8 = PrisonersCell8.size(); PrisonerCounter8 = uint8(PrisonersCell8.size());
HandleGameObject(PrisonCellGUIDs[DATA_PRISON_CELL8 - DATA_PRISON_CELL1], false); HandleGameObject(PrisonCellGUIDs[DATA_PRISON_CELL8 - DATA_PRISON_CELL1], false);
} }
@@ -242,12 +242,12 @@ class instance_blood_furnace : public InstanceMapScript
if (posX >= 405.0f && posX <= 423.0f && posZ <= 17) if (posX >= 405.0f && posX <= 423.0f && posZ <= 17)
{ {
if (posY >= 106.0f && posY <= 123.0f && posZ <= 17) if (posY >= 106.0f && posY <= 123.0f)
{ {
PrisonersCell5.insert(creature->GetGUID()); PrisonersCell5.insert(creature->GetGUID());
++PrisonerCounter5; ++PrisonerCounter5;
} }
else if (posY >= 76.0f && posY <= 91.0f && posZ <= 17) else if (posY >= 76.0f && posY <= 91.0f)
{ {
PrisonersCell6.insert(creature->GetGUID()); PrisonersCell6.insert(creature->GetGUID());
++PrisonerCounter6; ++PrisonerCounter6;
@@ -256,12 +256,12 @@ class instance_blood_furnace : public InstanceMapScript
} }
else if (posX >= 490.0f && posX <= 506.0f && posZ <= 17) else if (posX >= 490.0f && posX <= 506.0f && posZ <= 17)
{ {
if (posY >= 106.0f && posY <= 123.0f && posZ <= 17) if (posY >= 106.0f && posY <= 123.0f)
{ {
PrisonersCell7.insert(creature->GetGUID()); PrisonersCell7.insert(creature->GetGUID());
++PrisonerCounter7; ++PrisonerCounter7;
} }
else if (posY >= 76.0f && posY <= 91.0f && posZ <= 17) else if (posY >= 76.0f && posY <= 91.0f)
{ {
PrisonersCell8.insert(creature->GetGUID()); PrisonersCell8.insert(creature->GetGUID());
++PrisonerCounter8; ++PrisonerCounter8;
+1 -1
View File
@@ -147,7 +147,7 @@ void CreateDir(boost::filesystem::path const& path)
return; return;
if (!fs::create_directory(path)) if (!fs::create_directory(path))
throw new std::runtime_error("Unable to create directory" + path.string()); throw std::runtime_error("Unable to create directory" + path.string());
} }
void Usage(char const* prg) void Usage(char const* prg)