Avoid integer overflow in MoveGoodsToStation

In case where input cargo amount > 255
This commit is contained in:
Jonathan G Rennison
2020-02-23 23:42:22 +00:00
parent fa73e42dfd
commit f2bc12bb21

View File

@@ -4339,7 +4339,7 @@ uint MoveGoodsToStation(CargoID type, uint amount, SourceType source_type, Sourc
uint owner = p.first->owner;
/* Multiply the amount by (company best / sum of best for each company) to get cargo allocated to a company
* and by (station rating / sum of ratings in a company) to get the result for a single station. */
p.second = amount * company_best[owner] * p.first->goods[type].rating / best_sum / company_sum[owner];
p.second = ((uint64) amount) * ((uint64) company_best[owner]) * ((uint64) p.first->goods[type].rating) / (best_sum * company_sum[owner]);
moving += p.second;
}