Cast to long to avoid overflow when multiplying by the health

This commit is contained in:
Arular101
2018-01-04 00:23:40 +01:00
committed by reaperrr
parent 32b0170785
commit 30acee38c9
9 changed files with 38 additions and 19 deletions

View File

@@ -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));
}
}