Cast to long to avoid overflow when multiplying by the health
This commit is contained in:
@@ -55,7 +55,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (self.IsDead || IsTraitDisabled)
|
||||
return;
|
||||
|
||||
if (health.HP >= Info.HealIfBelow * health.MaxHP / 100)
|
||||
// Cast to long to avoid overflow when multiplying by the health
|
||||
if (health.HP >= Info.HealIfBelow * (long)health.MaxHP / 100)
|
||||
return;
|
||||
|
||||
if (damageTicks > 0)
|
||||
@@ -67,7 +68,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (--ticks <= 0)
|
||||
{
|
||||
ticks = Info.Delay;
|
||||
self.InflictDamage(self, new Damage(-(Info.Step + Info.PercentageStep * health.MaxHP / 100), Info.DamageTypes));
|
||||
|
||||
// Cast to long to avoid overflow when multiplying by the health
|
||||
self.InflictDamage(self, new Damage((int)(-(Info.Step + Info.PercentageStep * (long)health.MaxHP / 100)), Info.DamageTypes));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user