aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkaelima <kaelima@live.se>2012-09-05 17:17:45 +0200
committerkaelima <kaelima@live.se>2012-09-05 17:18:05 +0200
commit7c971be3c58b3c2f2628cb27f08515c9fafbf081 (patch)
treec31891823116bc882fb0398eb0571be05887c7f8 /src
parent0f21634eabf7ae04bb9bb0cab75fc8ee2b05252b (diff)
Core/Misc: Fix some warnings and logic mistakes found by static code analysis
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Battlefield/Battlefield.cpp4
-rwxr-xr-xsrc/server/game/Battlegrounds/Zones/BattlegroundWS.cpp1
-rwxr-xr-xsrc/server/game/Entities/Unit/Unit.cpp39
-rwxr-xr-xsrc/server/game/Loot/LootMgr.cpp2
-rwxr-xr-xsrc/server/game/Spells/Auras/SpellAuraEffects.cpp2
-rwxr-xr-xsrc/server/game/Spells/Auras/SpellAuras.cpp2
-rwxr-xr-xsrc/server/game/Spells/Spell.cpp2
-rwxr-xr-xsrc/server/game/Spells/SpellEffects.cpp8
-rwxr-xr-xsrc/server/game/Spells/SpellMgr.cpp2
-rw-r--r--src/server/scripts/Northrend/VioletHold/violet_hold.cpp7
-rw-r--r--src/server/scripts/Outland/shadowmoon_valley.cpp38
-rwxr-xr-xsrc/server/shared/Cryptography/BigNumber.cpp2
12 files changed, 55 insertions, 54 deletions
diff --git a/src/server/game/Battlefield/Battlefield.cpp b/src/server/game/Battlefield/Battlefield.cpp
index c0cf64ead58..eecee6268ed 100644
--- a/src/server/game/Battlefield/Battlefield.cpp
+++ b/src/server/game/Battlefield/Battlefield.cpp
@@ -451,8 +451,8 @@ WorldPacket Battlefield::BuildWarningAnnPacket(std::string msg)
data << uint32(1);
data << uint8(0);
data << uint64(0);
- data << uint32(strlen(msg.c_str()) + 1);
- data << msg.c_str();
+ data << uint32(msg.length());
+ data << msg;
data << uint8(0);
return data;
diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundWS.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundWS.cpp
index 8df6f93a082..e4803af8a21 100755
--- a/src/server/game/Battlegrounds/Zones/BattlegroundWS.cpp
+++ b/src/server/game/Battlegrounds/Zones/BattlegroundWS.cpp
@@ -731,7 +731,6 @@ void BattlegroundWS::Reset()
_bothFlagsKept = false;
_flagDebuffState = 0;
_flagSpellForceTimer = 0;
- _lastFlagCaptureTeam = 0;
_flagsDropTimer[BG_TEAM_ALLIANCE] = 0;
_flagsDropTimer[BG_TEAM_HORDE] = 0;
_flagsTimer[BG_TEAM_ALLIANCE] = 0;
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index 5d397790b44..27e2cbf358b 100755
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -381,9 +381,7 @@ void Unit::MonsterMoveWithSpeed(float x, float y, float z, float speed)
void Unit::UpdateSplineMovement(uint32 t_diff)
{
- enum{
- POSITION_UPDATE_DELAY = 400,
- };
+ uint32 const positionUpdateDelay = 400;
if (movespline->Finalized())
return;
@@ -397,7 +395,7 @@ void Unit::UpdateSplineMovement(uint32 t_diff)
m_movesplineTimer.Update(t_diff);
if (m_movesplineTimer.Passed() || arrived)
{
- m_movesplineTimer.Reset(POSITION_UPDATE_DELAY);
+ m_movesplineTimer.Reset(positionUpdateDelay);
Movement::Location loc = movespline->ComputePosition();
if (HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT))
@@ -543,12 +541,11 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
GetAI()->DamageDealt(victim, damage, damagetype);
if (victim->GetTypeId() == TYPEID_PLAYER)
+ {
if (victim->ToPlayer()->GetCommandStatus(CHEAT_GOD))
return 0;
- // Signal to pets that their owner was attacked
- if (victim->GetTypeId() == TYPEID_PLAYER)
- {
+ // Signal to pets that their owner was attacked
Pet* pet = victim->ToPlayer()->GetPet();
if (pet && pet->isAlive())
@@ -6728,10 +6725,13 @@ bool Unit::HandleDummyAuraProc(Unit* victim, uint32 damage, AuraEffect* triggere
// Judgement of Light
case 20185:
{
- // 2% of base mana
- basepoints0 = int32(victim->CountPctFromMaxHealth(2));
- victim->CastCustomSpell(victim, 20267, &basepoints0, 0, 0, true, 0, triggeredByAura);
- return true;
+ if (!victim)
+ return false;
+
+ // 2% of base mana
+ basepoints0 = int32(victim->CountPctFromMaxHealth(2));
+ victim->CastCustomSpell(victim, 20267, &basepoints0, 0, 0, true, 0, triggeredByAura);
+ return true;
}
// Judgement of Wisdom
case 20186:
@@ -16149,7 +16149,8 @@ void Unit::RemoveCharmedBy(Unit* charmer)
if (Creature* creature = ToCreature())
{
- creature->AI()->OnCharmed(false);
+ if (creature->AI())
+ creature->AI()->OnCharmed(false);
if (type != CHARM_TYPE_VEHICLE) // Vehicles' AI is never modified
{
@@ -17049,6 +17050,7 @@ void Unit::_EnterVehicle(Vehicle* vehicle, int8 seatId, AuraApplication const* a
sLog->outDebug(LOG_FILTER_VEHICLES, "EnterVehicle: %u leave vehicle %u seat %d and enter %d.", GetEntry(), m_vehicle->GetBase()->GetEntry(), GetTransSeat(), seatId);
ChangeSeat(seatId);
}
+
return;
}
else
@@ -17084,6 +17086,7 @@ void Unit::_EnterVehicle(Vehicle* vehicle, int8 seatId, AuraApplication const* a
ASSERT(!m_vehicle);
m_vehicle = vehicle;
+
if (!m_vehicle->AddPassenger(this, seatId))
{
m_vehicle = NULL;
@@ -17136,9 +17139,11 @@ void Unit::_ExitVehicle(Position const* exitPosition)
m_vehicle->RemovePassenger(this);
+ Player* player = ToPlayer();
+
// If player is on mouted duel and exits the mount should immediatly lose the duel
- if (GetTypeId() == TYPEID_PLAYER && ToPlayer()->duel && ToPlayer()->duel->isMounted)
- ToPlayer()->DuelComplete(DUEL_FLED);
+ if (player && player->duel && player->duel->isMounted)
+ player->DuelComplete(DUEL_FLED);
// This should be done before dismiss, because there may be some aura removal
Vehicle* vehicle = m_vehicle;
@@ -17155,8 +17160,8 @@ void Unit::_ExitVehicle(Position const* exitPosition)
AddUnitState(UNIT_STATE_MOVE);
- if (GetTypeId() == TYPEID_PLAYER)
- ToPlayer()->SetFallInformation(0, GetPositionZ());
+ if (player)
+ player->SetFallInformation(0, GetPositionZ());
else if (HasUnitMovementFlag(MOVEMENTFLAG_ROOT))
{
WorldPacket data(SMSG_SPLINE_MOVE_UNROOT, 8);
@@ -17172,7 +17177,7 @@ void Unit::_ExitVehicle(Position const* exitPosition)
//GetMotionMaster()->MoveFall(); // Enable this once passenger positions are calculater properly (see above)
- if (Player* player = ToPlayer())
+ if (player)
player->ResummonPetTemporaryUnSummonedIfAny();
if (vehicle->GetBase()->HasUnitTypeMask(UNIT_MASK_MINION))
diff --git a/src/server/game/Loot/LootMgr.cpp b/src/server/game/Loot/LootMgr.cpp
index 72636a5d2aa..fca8d78a3de 100755
--- a/src/server/game/Loot/LootMgr.cpp
+++ b/src/server/game/Loot/LootMgr.cpp
@@ -524,7 +524,7 @@ QuestItemList* Loot::FillQuestLoot(Player* player)
// increase once if one looter only, looter-times if free for all
if (item.freeforall || !item.is_blocked)
++unlootedCount;
- if (!player->GetGroup() || (player->GetGroup()->GetLootMethod() != GROUP_LOOT || player->GetGroup()->GetLootMethod() != ROUND_ROBIN))
+ if (!player->GetGroup() || (player->GetGroup()->GetLootMethod() != GROUP_LOOT && player->GetGroup()->GetLootMethod() != ROUND_ROBIN))
item.is_blocked = true;
if (items.size() + ql->size() == MAX_NR_LOOT_ITEMS)
diff --git a/src/server/game/Spells/Auras/SpellAuraEffects.cpp b/src/server/game/Spells/Auras/SpellAuraEffects.cpp
index bca26bd7391..29dcde9d616 100755
--- a/src/server/game/Spells/Auras/SpellAuraEffects.cpp
+++ b/src/server/game/Spells/Auras/SpellAuraEffects.cpp
@@ -5042,7 +5042,7 @@ void AuraEffect::HandleAuraDummy(AuraApplication const* aurApp, uint8 mode, bool
}
case 43681: // Inactive
{
- if (!target || target->GetTypeId() != TYPEID_PLAYER || aurApp->GetRemoveMode() != AURA_REMOVE_BY_EXPIRE)
+ if (target->GetTypeId() != TYPEID_PLAYER || aurApp->GetRemoveMode() != AURA_REMOVE_BY_EXPIRE)
return;
if (target->GetMap()->IsBattleground())
diff --git a/src/server/game/Spells/Auras/SpellAuras.cpp b/src/server/game/Spells/Auras/SpellAuras.cpp
index fb1cdc576ba..d94e6b0e9e6 100755
--- a/src/server/game/Spells/Auras/SpellAuras.cpp
+++ b/src/server/game/Spells/Auras/SpellAuras.cpp
@@ -425,7 +425,7 @@ void Aura::_UnapplyForTarget(Unit* target, Unit* caster, AuraApplication * auraA
if (itr == m_applications.end())
{
sLog->outError(LOG_FILTER_SPELLS_AURAS, "Aura::_UnapplyForTarget, target:%u, caster:%u, spell:%u was not found in owners application map!",
- target->GetGUIDLow(), caster->GetGUIDLow(), auraApp->GetBase()->GetSpellInfo()->Id);
+ target->GetGUIDLow(), caster ? caster->GetGUIDLow() : 0, auraApp->GetBase()->GetSpellInfo()->Id);
ASSERT(false);
}
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp
index e64197b5242..1dcee6dbac7 100755
--- a/src/server/game/Spells/Spell.cpp
+++ b/src/server/game/Spells/Spell.cpp
@@ -2525,7 +2525,7 @@ void Spell::DoAllEffectOnTarget(TargetInfo* target)
}
}
- if (missInfo != SPELL_MISS_EVADE && m_caster && !m_caster->IsFriendlyTo(unit) && (!m_spellInfo->IsPositive() || m_spellInfo->HasEffect(SPELL_EFFECT_DISPEL)))
+ if (missInfo != SPELL_MISS_EVADE && !m_caster->IsFriendlyTo(unit) && (!m_spellInfo->IsPositive() || m_spellInfo->HasEffect(SPELL_EFFECT_DISPEL)))
{
m_caster->CombatStart(unit, !(m_spellInfo->AttributesEx3 & SPELL_ATTR3_NO_INITIAL_AGGRO));
diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp
index 3637bb18049..ad9298f0144 100755
--- a/src/server/game/Spells/SpellEffects.cpp
+++ b/src/server/game/Spells/SpellEffects.cpp
@@ -1724,8 +1724,7 @@ void Spell::DoCreateItem(uint32 /*i*/, uint32 itemtype)
pItem->SetUInt32Value(ITEM_FIELD_CREATOR, player->GetGUIDLow());
// send info to the client
- if (pItem)
- player->SendNewItem(pItem, num_to_add, true, bgType == 0);
+ player->SendNewItem(pItem, num_to_add, true, bgType == 0);
// we succeeded in creating at least one item, so a levelup is possible
if (bgType == 0)
@@ -2079,7 +2078,8 @@ void Spell::EffectOpenLock(SpellEffIndex effIndex)
bg->EventPlayerClickedOnFlag(player, gameObjTarget);
return;
}
- }else if (m_spellInfo->Id == 1842 && gameObjTarget->GetGOInfo()->type == GAMEOBJECT_TYPE_TRAP && gameObjTarget->GetOwner())
+ }
+ else if (m_spellInfo->Id == 1842 && gameObjTarget->GetGOInfo()->type == GAMEOBJECT_TYPE_TRAP && gameObjTarget->GetOwner())
{
gameObjTarget->SetLootState(GO_JUST_DEACTIVATED);
return;
@@ -2116,7 +2116,7 @@ void Spell::EffectOpenLock(SpellEffIndex effIndex)
if (gameObjTarget)
SendLoot(guid, LOOT_SKINNING);
- else
+ else if (itemTarget)
itemTarget->SetFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_UNLOCKED);
// not allow use skill grow at item base open
diff --git a/src/server/game/Spells/SpellMgr.cpp b/src/server/game/Spells/SpellMgr.cpp
index e17e71f8869..f718b118ad7 100755
--- a/src/server/game/Spells/SpellMgr.cpp
+++ b/src/server/game/Spells/SpellMgr.cpp
@@ -1135,7 +1135,7 @@ bool SpellArea::IsFitToRequirements(Player const* player, uint32 newZone, uint32
case 68719: // Oil Refinery - Isle of Conquest.
case 68720: // Quarry - Isle of Conquest.
{
- if (player->GetBattlegroundTypeId() != BATTLEGROUND_IC || !player->GetBattleground())
+ if (!player || player->GetBattlegroundTypeId() != BATTLEGROUND_IC || !player->GetBattleground())
return false;
uint8 nodeType = spellId == 68719 ? NODE_TYPE_REFINERY : NODE_TYPE_QUARRY;
diff --git a/src/server/scripts/Northrend/VioletHold/violet_hold.cpp b/src/server/scripts/Northrend/VioletHold/violet_hold.cpp
index 122d051f1dd..870ea893b78 100644
--- a/src/server/scripts/Northrend/VioletHold/violet_hold.cpp
+++ b/src/server/scripts/Northrend/VioletHold/violet_hold.cpp
@@ -782,10 +782,13 @@ struct violet_hold_trashAI : public npc_escortAI
void JustDied(Unit* /*killer*/)
{
- if (Creature* portal = Unit::GetCreature((*me), instance->GetData64(DATA_TELEPORTATION_PORTAL)))
- CAST_AI(npc_teleportation_portal_vh::npc_teleportation_portalAI, portal->AI())->SummonedMobDied(me);
if (instance)
+ {
+ if (Creature* portal = Unit::GetCreature((*me), instance->GetData64(DATA_TELEPORTATION_PORTAL)))
+ CAST_AI(npc_teleportation_portal_vh::npc_teleportation_portalAI, portal->AI())->SummonedMobDied(me);
+
instance->SetData(DATA_NPC_PRESENCE_AT_DOOR_REMOVE, 1);
+ }
}
void CreatureStartAttackDoor()
diff --git a/src/server/scripts/Outland/shadowmoon_valley.cpp b/src/server/scripts/Outland/shadowmoon_valley.cpp
index 1656f7221ed..078f8f5a4f0 100644
--- a/src/server/scripts/Outland/shadowmoon_valley.cpp
+++ b/src/server/scripts/Outland/shadowmoon_valley.cpp
@@ -839,19 +839,10 @@ public:
return 1500;
break;
case 16:
- if (player)
- {
- Illi->CastSpell(player, SPELL_TWO, true);
- player->RemoveAurasDueToSpell(SPELL_THREE);
- player->RemoveAurasDueToSpell(SPELL_FOUR);
- return 5000;
- }
- else
- {
- player->FailQuest(QUEST_LORD_ILLIDAN_STORMRAGE);
- Step = 30;
- return 100;
- }
+ Illi->CastSpell(player, SPELL_TWO, true);
+ player->RemoveAurasDueToSpell(SPELL_THREE);
+ player->RemoveAurasDueToSpell(SPELL_FOUR);
+ return 5000;
break;
case 17:
DoScriptText(LORD_ILLIDAN_SAY_5, Illi);
@@ -1871,8 +1862,8 @@ public:
enum ZuluhedChains
{
- QUEST_ZULUHED = 10866,
- NPC_KARYNAKU = 22112,
+ QUEST_ZULUHED = 10866,
+ NPC_KARYNAKU = 22112,
};
class spell_unlocking_zuluheds_chains : public SpellScriptLoader
@@ -1884,18 +1875,21 @@ class spell_unlocking_zuluheds_chains : public SpellScriptLoader
{
PrepareSpellScript(spell_unlocking_zuluheds_chains_SpellScript);
- void HandleOnCast()
+ bool Load()
+ {
+ return GetCaster()->GetTypeId() == TYPEID_PLAYER;
+ }
+
+ void HandleAfterHit()
{
- // FIXME: Hackish solution, a better way to reward killcredit should be found
- if (Unit* caster = GetCaster())
- if(Player* player = caster->ToPlayer())
- if (player->GetQuestStatus(QUEST_ZULUHED) == QUEST_STATUS_INCOMPLETE)
- player->CastedCreatureOrGO(NPC_KARYNAKU, MAKE_NEW_GUID(0, NPC_KARYNAKU, HIGHGUID_UNIT), 0);
+ Player* caster = GetCaster()->ToPlayer();
+ if (caster->GetQuestStatus(QUEST_ZULUHED) == QUEST_STATUS_INCOMPLETE)
+ caster->KilledMonsterCredit(NPC_KARYNAKU, 0);
}
void Register()
{
- OnCast += SpellCastFn(spell_unlocking_zuluheds_chains_SpellScript::HandleOnCast);
+ AfterHit += SpellHitFn(spell_unlocking_zuluheds_chains_SpellScript::HandleAfterHit);
}
};
diff --git a/src/server/shared/Cryptography/BigNumber.cpp b/src/server/shared/Cryptography/BigNumber.cpp
index 146b2c37ad3..8e424e9bcdb 100755
--- a/src/server/shared/Cryptography/BigNumber.cpp
+++ b/src/server/shared/Cryptography/BigNumber.cpp
@@ -164,7 +164,7 @@ uint32 BigNumber::AsDword()
bool BigNumber::isZero() const
{
- return BN_is_zero(_bn)!=0;
+ return BN_is_zero(_bn);
}
uint8 *BigNumber::AsByteArray(int minSize, bool reverse)