1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-30 07:34:37 +01:00

Codefix: use constructor to set index of PoolItems over 'magic'/UB

This commit is contained in:
Rubidium
2026-01-03 13:31:04 +01:00
committed by rubidium42
parent ee9e8ab9b2
commit 2e6f8fe191
53 changed files with 165 additions and 149 deletions

View File

@@ -23,20 +23,23 @@ INSTANTIATE_POOL_METHODS(CargoPacket)
/**
* Create a new packet for savegame loading.
* @param index Index into the cargo packet pool.
*/
CargoPacket::CargoPacket()
CargoPacket::CargoPacket(CargoPacketID index) : CargoPacketPool::PoolItem<&_cargopacket_pool>(index)
{
}
/**
* Creates a new cargo packet.
*
* @param index Index into the cargo packet pool.
* @param first_station Source station of the packet.
* @param count Number of cargo entities to put in this packet.
* @param source Source of the packet (for subsidies).
* @pre count != 0
*/
CargoPacket::CargoPacket(StationID first_station,uint16_t count, Source source) :
CargoPacket::CargoPacket(CargoPacketID index, StationID first_station,uint16_t count, Source source) :
CargoPacketPool::PoolItem<&_cargopacket_pool>(index),
count(count),
source(source),
first_station(first_station)
@@ -47,13 +50,15 @@ CargoPacket::CargoPacket(StationID first_station,uint16_t count, Source source)
/**
* Create a new cargo packet. Used for older savegames to load in their partial data.
*
* @param index Index into the cargo packet pool.
* @param count Number of cargo entities to put in this packet.
* @param periods_in_transit Number of cargo aging periods the cargo has been in transit.
* @param first_station Station the cargo was initially loaded.
* @param source_xy Station location the cargo was initially loaded.
* @param feeder_share Feeder share the packet has already accumulated.
*/
CargoPacket::CargoPacket(uint16_t count, uint16_t periods_in_transit, StationID first_station, TileIndex source_xy, Money feeder_share) :
CargoPacket::CargoPacket(CargoPacketID index, uint16_t count, uint16_t periods_in_transit, StationID first_station, TileIndex source_xy, Money feeder_share) :
CargoPacketPool::PoolItem<&_cargopacket_pool>(index),
count(count),
periods_in_transit(periods_in_transit),
feeder_share(feeder_share),
@@ -66,11 +71,13 @@ CargoPacket::CargoPacket(uint16_t count, uint16_t periods_in_transit, StationID
/**
* Creates a new cargo packet. Used when loading or splitting packets.
*
* @param index Index into the cargo packet pool.
* @param count Number of cargo entities to put in this packet.
* @param feeder_share Feeder share the packet has already accumulated.
* @param original The original packet we are splitting.
*/
CargoPacket::CargoPacket(uint16_t count, Money feeder_share, CargoPacket &original) :
CargoPacket::CargoPacket(CargoPacketID index, uint16_t count, Money feeder_share, CargoPacket &original) :
CargoPacketPool::PoolItem<&_cargopacket_pool>(index),
count(count),
periods_in_transit(original.periods_in_transit),
feeder_share(feeder_share),