From 82cbd9152d51befdaaa7894752df4c14d1bb2aec Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Tue, 9 Dec 2008 11:47:49 +0300 Subject: [PATCH] Fixed possible crash in Aura::HandleModPossessPet Also small code cleanup. --- src/game/Pet.cpp | 32 ++++++++++++++++++-------------- src/game/SpellAuras.cpp | 5 ++++- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index ef5898b2c..2dbdd5dc8 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -1524,24 +1524,28 @@ void Pet::ToggleAutocast(uint32 spellid, bool apply) if(apply) { - for (i = 0; i < m_autospells.size() && m_autospells[i] != spellid; i++); - if (i == m_autospells.size()) - { - m_autospells.push_back(spellid); - itr->second->active = ACT_ENABLED; - itr->second->state = PETSPELL_CHANGED; - } + for (i = 0; i < m_autospells.size() && m_autospells[i] != spellid; i++) + ; // just search + + if (i == m_autospells.size()) + { + m_autospells.push_back(spellid); + itr->second->active = ACT_ENABLED; + itr->second->state = PETSPELL_CHANGED; + } } else { AutoSpellList::iterator itr2 = m_autospells.begin(); - for (i = 0; i < m_autospells.size() && m_autospells[i] != spellid; i++, itr2++); - if (i < m_autospells.size()) - { - m_autospells.erase(itr2); - itr->second->active = ACT_DISABLED; - itr->second->state = PETSPELL_CHANGED; - } + for (i = 0; i < m_autospells.size() && m_autospells[i] != spellid; i++, itr2++) + ; // just search + + if (i < m_autospells.size()) + { + m_autospells.erase(itr2); + itr->second->active = ACT_DISABLED; + itr->second->state = PETSPELL_CHANGED; + } } } diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp index 519e28ad0..edf78f86c 100644 --- a/src/game/SpellAuras.cpp +++ b/src/game/SpellAuras.cpp @@ -3030,8 +3030,11 @@ void Aura::HandleModPossessPet(bool apply, bool Real) return; Unit* caster = GetCaster(); + if(!caster || caster->GetTypeId() != TYPEID_PLAYER) + return; + Pet *pet = caster->GetPet(); - if(!pet || (pet != m_target) || !caster || (caster->GetTypeId() != TYPEID_PLAYER)) + if(!pet || pet != m_target) return; if(apply)