1
0
Fork 0

Fix: multiplication result converted to larger type

Technically unlikely to happen, though uint16 * uint16 get promoted to int and
then stored as uint64; similarly uint * uint16 remains uint and gets stored as
uint64. In both cases the value can get truncated before the change to uint64.
pull/10719/head
Rubidium 2023-05-14 21:13:24 +02:00 committed by rubidium42
parent 4894da67da
commit 4a6fdc8293
1 changed files with 2 additions and 2 deletions

View File

@ -180,7 +180,7 @@ void CargoList<Tinst, Tcont>::RemoveFromCache(const CargoPacket *cp, uint count)
{
assert(count <= cp->count);
this->count -= count;
this->cargo_days_in_transit -= cp->days_in_transit * count;
this->cargo_days_in_transit -= static_cast<uint64_t>(cp->days_in_transit) * count;
}
/**
@ -192,7 +192,7 @@ template <class Tinst, class Tcont>
void CargoList<Tinst, Tcont>::AddToCache(const CargoPacket *cp)
{
this->count += cp->count;
this->cargo_days_in_transit += cp->days_in_transit * cp->count;
this->cargo_days_in_transit += static_cast<uint64_t>(cp->days_in_transit) * cp->count;
}
/** Invalidates the cached data and rebuilds it. */