Skip to content

Commit 2fd98c9

Browse files
authored
Merge pull request #4476 from Goober5000/fix_4472
use proper bounds check when bashing hull in red-alert
2 parents 0ab523b + 324ccf3 commit 2fd98c9

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

code/missionui/redalert.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,8 +885,14 @@ void red_alert_bash_wingman_status()
885885
mprintf(("Invalid ship class specified in red alert data for ship %s. Using mission defaults.\n", shipp->ship_name));
886886
}
887887

888+
float max_hull;
889+
if (shipp->special_hitpoints)
890+
max_hull = shipp->ship_max_hull_strength;
891+
else
892+
max_hull = Ship_info[shipp->ship_info_index].max_hull_strength;
893+
888894
// restore hull (but not shields)
889-
if (ras->hull >= 0.0f && ras->hull <= ship_objp->hull_strength)
895+
if (ras->hull >= 0.0f && ras->hull <= max_hull)
890896
ship_objp->hull_strength = ras->hull;
891897
else
892898
mprintf(("Invalid health in red alert data for ship %s. Using mission defaults.\n", shipp->ship_name));
@@ -979,9 +985,15 @@ void red_alert_bash_wingman_status()
979985
}
980986
}
981987

988+
float max_hull;
989+
if (pobjp->special_hitpoints)
990+
max_hull = pobjp->ship_max_hull_strength;
991+
else
992+
max_hull = Ship_info[pobjp->ship_class].max_hull_strength;
993+
982994
// restore hull (but not shields)
983-
if (ras->hull >= 0.0f && ras->hull <= (pobjp->initial_hull * pobjp->ship_max_hull_strength / 100.0f))
984-
pobjp->initial_hull = (int) (ras->hull * 100.0f / pobjp->ship_max_hull_strength);
995+
if (ras->hull >= 0.0f && ras->hull <= max_hull)
996+
pobjp->initial_hull = (int) (ras->hull * 100.0f / max_hull);
985997
else
986998
mprintf(("Invalid health in red alert data for ship %s. Using mission defaults.\n", pobjp->name));
987999

0 commit comments

Comments
 (0)