fix(Core): Fixed a few crashes/bugs that were found via static code analysis (#2617)

This commit is contained in:
Kaev
2020-01-25 14:26:38 +01:00
committed by Stoabrogga
parent 1bbe10dc33
commit 999d588c37
21 changed files with 80 additions and 59 deletions

View File

@@ -501,7 +501,7 @@ inline void KillRewarder::_InitXP(Player* player)
// * on battlegrounds;
// * otherwise, not in PvP;
// * not if killer is on vehicle.
if (_isBattleGround || (!_isPvP && !_killer->GetVehicle()))
if (_victim && (_isBattleGround || (!_isPvP && !_killer->GetVehicle())))
_xp = acore::XP::Gain(player, _victim, _isBattleGround);
if (_xp && !_isBattleGround && _victim) // pussywizard: npcs with relatively low hp give lower exp
@@ -7845,7 +7845,7 @@ void Player::DuelComplete(DuelCompleteType type)
duel->opponent->CastSpell(duel->opponent, 52994, true);
// Honor points after duel (the winner) - ImpConfig
if (uint32 amount = sWorld->getIntConfig(CONFIG_HONOR_AFTER_DUEL))
if (uint32 amount = sWorld->getIntConfig(CONFIG_HONOR_AFTER_DUEL) && duel->opponent)
duel->opponent->RewardHonor(NULL, 1, amount);
break;
@@ -15840,8 +15840,6 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
{
if (quest->RequiredItemCount[i] > 0 && itemTemplate->Bonding == BIND_QUEST_ITEM && !quest->IsRepeatable() && !HasQuestForItem(quest->RequiredItemId[i], quest_id, true))
DestroyItemCount(quest->RequiredItemId[i], quest->RequiredItemCount[i], true);
else
DestroyItemCount(quest->RequiredItemId[i], quest->RequiredItemCount[i], true);
}
}
for (uint8 i = 0; i < QUEST_SOURCE_ITEM_IDS_COUNT; ++i)
@@ -15850,8 +15848,6 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
{
if (quest->ItemDropQuantity[i] > 0 && itemTemplate->Bonding == BIND_QUEST_ITEM && !quest->IsRepeatable() && !HasQuestForItem(quest->ItemDrop[i], quest_id))
DestroyItemCount(quest->ItemDrop[i], quest->ItemDropQuantity[i], true);
else
DestroyItemCount(quest->ItemDrop[i], quest->ItemDropQuantity[i], true);
}
}

View File

@@ -379,7 +379,7 @@ bool Group::AddMember(Player* player)
SubGroupCounterIncrease(subGroup);
//if (player)
if (player)
{
player->SetGroupInvite(NULL);
if (player->GetGroup())

View File

@@ -1050,25 +1050,25 @@ void WorldSession::HandleRequestPartyMemberStatsOpcode(WorldPacket &recvData)
data.put<uint64>(maskPos, auraMask); // GROUP_UPDATE_FLAG_AURAS
if (updateFlags & GROUP_UPDATE_FLAG_PET_GUID)
if (pet && (updateFlags & GROUP_UPDATE_FLAG_PET_GUID))
data << uint64(pet->GetGUID());
data << std::string(pet ? pet->GetName() : ""); // GROUP_UPDATE_FLAG_PET_NAME
data << uint16(pet ? pet->GetDisplayId() : 0); // GROUP_UPDATE_FLAG_PET_MODEL_ID
if (updateFlags & GROUP_UPDATE_FLAG_PET_CUR_HP)
if (pet && (updateFlags & GROUP_UPDATE_FLAG_PET_CUR_HP))
data << uint32(pet->GetHealth());
if (updateFlags & GROUP_UPDATE_FLAG_PET_MAX_HP)
if (pet && (updateFlags & GROUP_UPDATE_FLAG_PET_MAX_HP))
data << uint32(pet->GetMaxHealth());
if (updateFlags & GROUP_UPDATE_FLAG_PET_POWER_TYPE)
if (pet && (updateFlags & GROUP_UPDATE_FLAG_PET_POWER_TYPE))
data << (uint8)pet->getPowerType();
if (updateFlags & GROUP_UPDATE_FLAG_PET_CUR_POWER)
if (pet && (updateFlags & GROUP_UPDATE_FLAG_PET_CUR_POWER))
data << uint16(pet->GetPower(pet->getPowerType()));
if (updateFlags & GROUP_UPDATE_FLAG_PET_MAX_POWER)
if (pet && (updateFlags & GROUP_UPDATE_FLAG_PET_MAX_POWER))
data << uint16(pet->GetMaxPower(pet->getPowerType()));
uint64 petAuraMask = 0;

View File

@@ -710,6 +710,7 @@ void WorldSession::HandleMailCreateTextItem(WorldPacket & recvData)
if (!mailTemplateEntry)
{
player->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR);
delete bodyItem;
return;
}

View File

@@ -254,7 +254,7 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater)
/// If necessary, kick the player because the client didn't send anything for too long
/// (or they've been idling in character select)
if (sWorld->getBoolConfig(CONFIG_CLOSE_IDLE_CONNECTIONS) && IsConnectionIdle())
if (sWorld->getBoolConfig(CONFIG_CLOSE_IDLE_CONNECTIONS) && IsConnectionIdle() && m_Socket)
m_Socket->CloseSocket("Client didn't send anything for too long");
}

View File

@@ -3267,7 +3267,7 @@ void AuraEffect::HandleModStateImmunityMask(AuraApplication const* aurApp, uint8
{
if (!GetAmount())
{
mechanic_immunity_list = (1 << MECHANIC_CHARM) | (1 << MECHANIC_SNARE) | (1 << MECHANIC_ROOT)
mechanic_immunity_list = (1 << MECHANIC_SNARE) | (1 << MECHANIC_ROOT)
| (1 << MECHANIC_FEAR) | (1 << MECHANIC_STUN)
| (1 << MECHANIC_SLEEP) | (1 << MECHANIC_CHARM)
| (1 << MECHANIC_SAPPED) | (1 << MECHANIC_HORROR)
@@ -6095,7 +6095,7 @@ void AuraEffect::HandlePeriodicDamageAurasTick(Unit* target, Unit* caster) const
if (GetAuraType() == SPELL_AURA_PERIODIC_DAMAGE)
{
// xinef: leave only target depending bonuses, rest is handled in calculate amount
if (GetBase()->GetType() == DYNOBJ_AURA_TYPE)
if (GetBase()->GetType() == DYNOBJ_AURA_TYPE && caster)
damage = caster->SpellDamageBonusDone(target, GetSpellInfo(), damage, DOT, 0.0f, GetBase()->GetStackAmount());
damage = target->SpellDamageBonusTaken(caster, GetSpellInfo(), damage, DOT, GetBase()->GetStackAmount());

View File

@@ -2839,7 +2839,7 @@ void Spell::DoAllEffectOnTarget(TargetInfo* target)
}
// Failed Pickpocket, reveal rogue
if (missInfo == SPELL_MISS_RESIST && m_spellInfo->HasAttribute(SPELL_ATTR0_CU_PICKPOCKET) && unitTarget->GetTypeId() == TYPEID_UNIT)
if (missInfo == SPELL_MISS_RESIST && m_spellInfo->HasAttribute(SPELL_ATTR0_CU_PICKPOCKET) && unitTarget->GetTypeId() == TYPEID_UNIT && m_caster)
{
m_caster->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_TALK);
if (unitTarget->ToCreature()->IsAIEnabled)

View File

@@ -3141,8 +3141,9 @@ void Spell::EffectSummonPet(SpellEffIndex effIndex)
uint32 petentry = m_spellInfo->Effects[effIndex].MiscValue;
int32 duration = m_spellInfo->GetDuration();
if(Player* modOwner = m_originalCaster->GetSpellModOwner())
modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DURATION, duration);
if (m_originalCaster)
if(Player* modOwner = m_originalCaster->GetSpellModOwner())
modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DURATION, duration);
if (!owner)
{
@@ -4644,21 +4645,20 @@ void Spell::EffectSummonObject(SpellEffIndex effIndex)
default: return;
}
uint64 guid = m_caster->m_ObjectSlot[slot];
if (guid != 0)
if (m_caster)
{
GameObject* gameObject = NULL;
if (m_caster)
gameObject = m_caster->GetMap()->GetGameObject(guid);
if (gameObject)
uint64 guid = m_caster->m_ObjectSlot[slot];
if (guid != 0)
{
// Recast case - null spell id to make auras not be removed on object remove from world
if (m_spellInfo->Id == gameObject->GetSpellId())
gameObject->SetSpellId(0);
m_caster->RemoveGameObject(gameObject, true);
if (GameObject* gameObject = m_caster->GetMap()->GetGameObject(guid))
{
// Recast case - null spell id to make auras not be removed on object remove from world
if (m_spellInfo->Id == gameObject->GetSpellId())
gameObject->SetSpellId(0);
m_caster->RemoveGameObject(gameObject, true);
}
m_caster->m_ObjectSlot[slot] = 0;
}
m_caster->m_ObjectSlot[slot] = 0;
}
GameObject* pGameObj = sObjectMgr->IsGameObjectStaticTransport(gameobjectId) ? new StaticTransport() : new GameObject();