Fix UnitMods. This fixes buffer overflows.

/me pokes @Fabi
This commit is contained in:
LordJZ 2012-08-12 08:43:46 +04:00 committed by Antz
parent adabb1556d
commit a5ca883668
2 changed files with 11 additions and 0 deletions

View file

@ -223,6 +223,8 @@ void Player::UpdateMaxHealth()
void Player::UpdateMaxPower(Powers power) void Player::UpdateMaxPower(Powers power)
{ {
MANGOS_ASSERT(power < MAX_POWERS);
UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + power); UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + power);
uint32 create_power = GetCreatePowers(power); uint32 create_power = GetCreatePowers(power);
@ -856,6 +858,8 @@ void Creature::UpdateMaxHealth()
void Creature::UpdateMaxPower(Powers power) void Creature::UpdateMaxPower(Powers power)
{ {
MANGOS_ASSERT(power < MAX_POWERS);
UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + power); UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + power);
float value = GetTotalAuraModValue(unitMod); float value = GetTotalAuraModValue(unitMod);
@ -1027,6 +1031,8 @@ void Pet::UpdateMaxHealth()
void Pet::UpdateMaxPower(Powers power) void Pet::UpdateMaxPower(Powers power)
{ {
MANGOS_ASSERT(power < MAX_POWERS);
UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + power); UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + power);
float addValue = (power == POWER_MANA) ? GetStat(STAT_INTELLECT) - GetCreateStat(STAT_INTELLECT) : 0.0f; float addValue = (power == POWER_MANA) ? GetStat(STAT_INTELLECT) - GetCreateStat(STAT_INTELLECT) : 0.0f;

View file

@ -332,8 +332,13 @@ enum UnitMods
UNIT_MOD_RAGE, UNIT_MOD_RAGE,
UNIT_MOD_FOCUS, UNIT_MOD_FOCUS,
UNIT_MOD_ENERGY, UNIT_MOD_ENERGY,
UNIT_MOD_HAPPINESS, // REQUIRED for fast indexing to work.
UNIT_MOD_RUNE, UNIT_MOD_RUNE,
UNIT_MOD_RUNIC_POWER, UNIT_MOD_RUNIC_POWER,
UNIT_MOD_SOUL_SHARDS,
UNIT_MOD_ECLIPSE,
UNIT_MOD_HOLY_POWER,
UNIT_MOD_ALTERNATE,
UNIT_MOD_ARMOR, // UNIT_MOD_ARMOR..UNIT_MOD_RESISTANCE_ARCANE must be in existing order, it's accessed by index values of SpellSchools enum. UNIT_MOD_ARMOR, // UNIT_MOD_ARMOR..UNIT_MOD_RESISTANCE_ARCANE must be in existing order, it's accessed by index values of SpellSchools enum.
UNIT_MOD_RESISTANCE_HOLY, UNIT_MOD_RESISTANCE_HOLY,
UNIT_MOD_RESISTANCE_FIRE, UNIT_MOD_RESISTANCE_FIRE,