fix(Core): potential crashes/bugs reported by static analysis #2 (#2622)

This commit is contained in:
Kaev
2020-02-03 07:52:27 +01:00
committed by GitHub
parent 8cfdfd0af0
commit 2fa9f5c249
30 changed files with 148 additions and 229 deletions

View File

@@ -7794,7 +7794,7 @@ bool Player::IsOutdoorPvPActive()
void Player::DuelComplete(DuelCompleteType type)
{
// duel not requested
if (!duel)
if (!duel || !duel->opponent || !duel->initiator)
return;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
@@ -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) && duel->opponent)
if (uint32 amount = sWorld->getIntConfig(CONFIG_HONOR_AFTER_DUEL))
duel->opponent->RewardHonor(NULL, 1, amount);
break;
@@ -8089,10 +8089,6 @@ void Player::_ApplyItemBonuses(ItemTemplate const* proto, uint8 slot, bool apply
ApplyRatingMod(CR_HIT_TAKEN_SPELL, int32(val), apply);
break;
case ITEM_MOD_CRIT_TAKEN_RATING:
ApplyRatingMod(CR_CRIT_TAKEN_MELEE, int32(val), apply);
ApplyRatingMod(CR_CRIT_TAKEN_RANGED, int32(val), apply);
ApplyRatingMod(CR_CRIT_TAKEN_SPELL, int32(val), apply);
break;
case ITEM_MOD_RESILIENCE_RATING:
ApplyRatingMod(CR_CRIT_TAKEN_MELEE, int32(val), apply);
ApplyRatingMod(CR_CRIT_TAKEN_RANGED, int32(val), apply);
@@ -10200,8 +10196,6 @@ uint8 Player::FindEquipSlot(ItemTemplate const* proto, uint32 slot, bool swap) c
slots[0] = EQUIPMENT_SLOT_BODY;
break;
case INVTYPE_CHEST:
slots[0] = EQUIPMENT_SLOT_CHEST;
break;
case INVTYPE_ROBE:
slots[0] = EQUIPMENT_SLOT_CHEST;
break;
@@ -10242,9 +10236,13 @@ uint8 Player::FindEquipSlot(ItemTemplate const* proto, uint32 slot, bool swap) c
break;
}
case INVTYPE_SHIELD:
case INVTYPE_WEAPONOFFHAND:
case INVTYPE_HOLDABLE:
slots[0] = EQUIPMENT_SLOT_OFFHAND;
break;
case INVTYPE_RANGED:
case INVTYPE_RANGEDRIGHT:
case INVTYPE_THROWN:
slots[0] = EQUIPMENT_SLOT_RANGED;
break;
case INVTYPE_2HWEAPON:
@@ -10278,18 +10276,6 @@ uint8 Player::FindEquipSlot(ItemTemplate const* proto, uint32 slot, bool swap) c
case INVTYPE_WEAPONMAINHAND:
slots[0] = EQUIPMENT_SLOT_MAINHAND;
break;
case INVTYPE_WEAPONOFFHAND:
slots[0] = EQUIPMENT_SLOT_OFFHAND;
break;
case INVTYPE_HOLDABLE:
slots[0] = EQUIPMENT_SLOT_OFFHAND;
break;
case INVTYPE_THROWN:
slots[0] = EQUIPMENT_SLOT_RANGED;
break;
case INVTYPE_RANGEDRIGHT:
slots[0] = EQUIPMENT_SLOT_RANGED;
break;
case INVTYPE_BAG:
slots[0] = INVENTORY_SLOT_BAG_START + 0;
slots[1] = INVENTORY_SLOT_BAG_START + 1;
@@ -12491,14 +12477,11 @@ void Player::SetAmmo(uint32 item)
return;
// check ammo
if (item)
InventoryResult msg = CanUseAmmo(item);
if (msg != EQUIP_ERR_OK)
{
InventoryResult msg = CanUseAmmo(item);
if (msg != EQUIP_ERR_OK)
{
SendEquipError(msg, NULL, NULL, item);
return;
}
SendEquipError(msg, NULL, NULL, item);
return;
}
SetUInt32Value(PLAYER_AMMO_ID, item);
@@ -13895,7 +13878,7 @@ void Player::SwapItem(uint16 src, uint16 dst)
}
}
if (!released && IsBagPos(dst) && pDstItem)
if (!released && IsBagPos(dst))
{
Bag* bag = pDstItem->ToBag();
for (uint32 i = 0; i < bag->GetBagSize(); ++i)