Avoid integer overflow in MoveGoodsToStation
In case where input cargo amount > 255
This commit is contained in:
@@ -4339,7 +4339,7 @@ uint MoveGoodsToStation(CargoID type, uint amount, SourceType source_type, Sourc
|
|||||||
uint owner = p.first->owner;
|
uint owner = p.first->owner;
|
||||||
/* Multiply the amount by (company best / sum of best for each company) to get cargo allocated to a company
|
/* 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. */
|
* 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;
|
moving += p.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user