Fix #157: Integer overflow in town GetNormalGrowthRate

This commit is contained in:
Jonathan G Rennison
2020-06-11 17:12:47 +01:00
parent 12c25be778
commit 3eb8d62148

View File

@@ -3727,9 +3727,9 @@ static uint GetNormalGrowthRate(Town *t)
return stat.old_max ? ((uint64) (stat.old_act << 15)) / stat.old_max : 1 << 15; return stat.old_max ? ((uint64) (stat.old_act << 15)) / stat.old_max : 1 << 15;
}; };
uint32 cargo_ratio_fix16 = calculate_cargo_ratio_fix15(t->supplied[CT_PASSENGERS]) + calculate_cargo_ratio_fix15(t->supplied[CT_MAIL]); uint32 cargo_ratio_fix16 = calculate_cargo_ratio_fix15(t->supplied[CT_PASSENGERS]) + calculate_cargo_ratio_fix15(t->supplied[CT_MAIL]);
uint32 cargo_dependant_part = (((uint64) cargo_ratio_fix16) * ((uint64) inverse_m) * _settings_game.economy.town_growth_cargo_transported) >> 16; uint64 cargo_dependant_part = (((uint64) cargo_ratio_fix16) * ((uint64) inverse_m) * _settings_game.economy.town_growth_cargo_transported) >> 16;
uint32 non_cargo_dependant_part = ((uint64) inverse_m) * (100 - _settings_game.economy.town_growth_cargo_transported); uint64 non_cargo_dependant_part = ((uint64) inverse_m) * (100 - _settings_game.economy.town_growth_cargo_transported);
uint32 total = (cargo_dependant_part + non_cargo_dependant_part); uint64 total = (cargo_dependant_part + non_cargo_dependant_part);
if (total == 0) { if (total == 0) {
ClrBit(t->flags, TOWN_IS_GROWING); ClrBit(t->flags, TOWN_IS_GROWING);
return UINT16_MAX; return UINT16_MAX;