Guard against integer underflow (#462)

This commit is contained in:
Asdow
2025-07-20 17:30:22 -07:00
committed by GitHub
parent 49a56d01ac
commit 7bb7c54317
+4 -3
View File
@@ -7151,15 +7151,16 @@ void InitializeGroup( const GROUP_TYPE groupType, const UINT8 groupSize, UINT8 &
tankCount++;
}
if ( gGameExternalOptions.fASDAssignsJeeps && ASDSoldierUpgradeToJeep( ) )
if ( troopCount > 0 && gGameExternalOptions.fASDAssignsJeeps && ASDSoldierUpgradeToJeep( ) )
{
troopCount--;
jeepCount++;
}
if ( gGameExternalOptions.fASDAssignsRobots && ASDSoldierUpgradeToRobot() )
if ( troopCount > 0 && gGameExternalOptions.fASDAssignsRobots && ASDSoldierUpgradeToRobot() )
{
const int numRobots = 1 + Random(difficultyMod);
// Limit amount of robots, if randomized difficulty bonus would cause us to go over the troopCount amount
const int numRobots = min( (1 + Random(difficultyMod)), troopCount);
troopCount -= numRobots;
robotCount += numRobots;
}