Cast to long to avoid overflow when multiplying by the health (part 2)

This commit is contained in:
Arular101
2018-01-10 18:12:37 +01:00
committed by reaperrr
parent 30acee38c9
commit 24b7f7a23f
6 changed files with 17 additions and 7 deletions

View File

@@ -58,7 +58,9 @@ namespace OpenRA.Mods.Common.Activities
return;
var capturesInfo = activeCaptures.Info;
var lowEnoughHealth = health.HP <= capturable.Info.CaptureThreshold * health.MaxHP / 100;
// Cast to long to avoid overflow when multiplying by the health
var lowEnoughHealth = health.HP <= (int)(capturable.Info.CaptureThreshold * (long)health.MaxHP / 100);
if (!capturesInfo.Sabotage || lowEnoughHealth || actor.Owner.NonCombatant)
{
var oldOwner = actor.Owner;
@@ -80,7 +82,8 @@ namespace OpenRA.Mods.Common.Activities
}
else
{
var damage = health.MaxHP * capturesInfo.SabotageHPRemoval / 100;
// Cast to long to avoid overflow when multiplying by the health
var damage = (int)((long)health.MaxHP * capturesInfo.SabotageHPRemoval / 100);
actor.InflictDamage(self, new Damage(damage));
}