Minor changes to avoid undefined behaviour warnings.
Avoid creating a reference from a nullptr. Avoid trying a malloc and memcpy into a 0 length buffer. Virtual trains should never be drawn.
This commit is contained in:
@@ -3664,8 +3664,11 @@ static void DuplicateTileTable(AirportSpec *as)
|
|||||||
MemCpyT(table_list[i], as->table[i], num_tiles);
|
MemCpyT(table_list[i], as->table[i], num_tiles);
|
||||||
}
|
}
|
||||||
as->table = table_list;
|
as->table = table_list;
|
||||||
HangarTileTable *depot_table = MallocT<HangarTileTable>(as->nof_depots);
|
HangarTileTable *depot_table = NULL;
|
||||||
MemCpyT(depot_table, as->depot_table, as->nof_depots);
|
if (as->nof_depots > 0) {
|
||||||
|
depot_table = MallocT<HangarTileTable>(as->nof_depots);
|
||||||
|
MemCpyT(depot_table, as->depot_table, as->nof_depots);
|
||||||
|
}
|
||||||
as->depot_table = depot_table;
|
as->depot_table = depot_table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -236,7 +236,7 @@ protected:
|
|||||||
/** stores track status (available trackdirs) for the new tile into m_new_td_bits */
|
/** stores track status (available trackdirs) for the new tile into m_new_td_bits */
|
||||||
inline bool QueryNewTileTrackStatus()
|
inline bool QueryNewTileTrackStatus()
|
||||||
{
|
{
|
||||||
CPerfStart perf(*m_pPerf);
|
CPerfStart perf(m_pPerf);
|
||||||
if (IsRailTT() && IsPlainRailTile(m_new_tile)) {
|
if (IsRailTT() && IsPlainRailTile(m_new_tile)) {
|
||||||
m_new_td_bits = (TrackdirBits)(GetTrackBits(m_new_tile) * 0x101);
|
m_new_td_bits = (TrackdirBits)(GetTrackBits(m_new_tile) * 0x101);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -51,7 +51,7 @@ struct CPerfStartReal
|
|||||||
{
|
{
|
||||||
CPerformanceTimer *m_pperf;
|
CPerformanceTimer *m_pperf;
|
||||||
|
|
||||||
inline CPerfStartReal(CPerformanceTimer& perf) : m_pperf(&perf)
|
inline CPerfStartReal(CPerformanceTimer* perf) : m_pperf(perf)
|
||||||
{
|
{
|
||||||
if (m_pperf != NULL) m_pperf->Start();
|
if (m_pperf != NULL) m_pperf->Start();
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,7 @@ struct CPerfStartReal
|
|||||||
|
|
||||||
struct CPerfStartFake
|
struct CPerfStartFake
|
||||||
{
|
{
|
||||||
inline CPerfStartFake(CPerformanceTimer& perf) {}
|
inline CPerfStartFake(CPerformanceTimer* perf) {}
|
||||||
inline ~CPerfStartFake() {}
|
inline ~CPerfStartFake() {}
|
||||||
inline void Stop() {}
|
inline void Stop() {}
|
||||||
};
|
};
|
||||||
|
@@ -94,7 +94,7 @@ protected:
|
|||||||
public:
|
public:
|
||||||
inline int SlopeCost(TileIndex tile, Trackdir td)
|
inline int SlopeCost(TileIndex tile, Trackdir td)
|
||||||
{
|
{
|
||||||
CPerfStart perf_cost(Yapf().m_perf_slope_cost);
|
CPerfStart perf_cost(&Yapf().m_perf_slope_cost);
|
||||||
if (!stSlopeCost(tile, td)) return 0;
|
if (!stSlopeCost(tile, td)) return 0;
|
||||||
return Yapf().PfGetSettings().rail_slope_penalty;
|
return Yapf().PfGetSettings().rail_slope_penalty;
|
||||||
}
|
}
|
||||||
@@ -280,7 +280,7 @@ public:
|
|||||||
{
|
{
|
||||||
int cost = 0;
|
int cost = 0;
|
||||||
/* if there is one-way signal in the opposite direction, then it is not our way */
|
/* if there is one-way signal in the opposite direction, then it is not our way */
|
||||||
CPerfStart perf_cost(Yapf().m_perf_other_cost);
|
CPerfStart perf_cost(&Yapf().m_perf_other_cost);
|
||||||
if (IsTileType(tile, MP_RAILWAY)) {
|
if (IsTileType(tile, MP_RAILWAY)) {
|
||||||
bool has_signal_against = HasSignalOnTrackdir(tile, ReverseTrackdir(trackdir));
|
bool has_signal_against = HasSignalOnTrackdir(tile, ReverseTrackdir(trackdir));
|
||||||
bool has_signal_along = HasSignalOnTrackdir(tile, trackdir);
|
bool has_signal_along = HasSignalOnTrackdir(tile, trackdir);
|
||||||
@@ -402,7 +402,7 @@ public:
|
|||||||
assert(tf->m_new_tile == n.m_key.m_tile);
|
assert(tf->m_new_tile == n.m_key.m_tile);
|
||||||
assert((TrackdirToTrackdirBits(n.m_key.m_td) & tf->m_new_td_bits) != TRACKDIR_BIT_NONE);
|
assert((TrackdirToTrackdirBits(n.m_key.m_td) & tf->m_new_td_bits) != TRACKDIR_BIT_NONE);
|
||||||
|
|
||||||
CPerfStart perf_cost(Yapf().m_perf_cost);
|
CPerfStart perf_cost(&Yapf().m_perf_cost);
|
||||||
|
|
||||||
/* Does the node have some parent node? */
|
/* Does the node have some parent node? */
|
||||||
bool has_parent = (n.m_parent != NULL);
|
bool has_parent = (n.m_parent != NULL);
|
||||||
|
@@ -296,10 +296,10 @@ uint Vehicle::Crash(bool flooded)
|
|||||||
*/
|
*/
|
||||||
bool Vehicle::IsDrawn() const
|
bool Vehicle::IsDrawn() const
|
||||||
{
|
{
|
||||||
return !(this->vehstatus & VS_HIDDEN) ||
|
return !(HasBit(this->subtype, GVSF_VIRTUAL)) && (!(this->vehstatus & VS_HIDDEN) ||
|
||||||
(IsTransparencySet(TO_TUNNELS) &&
|
(IsTransparencySet(TO_TUNNELS) &&
|
||||||
((this->type == VEH_TRAIN && Train::From(this)->track == TRACK_BIT_WORMHOLE) ||
|
((this->type == VEH_TRAIN && Train::From(this)->track == TRACK_BIT_WORMHOLE) ||
|
||||||
(this->type == VEH_ROAD && RoadVehicle::From(this)->state == RVSB_WORMHOLE)));
|
(this->type == VEH_ROAD && RoadVehicle::From(this)->state == RVSB_WORMHOLE))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user