1
0
Fork 0

Codechange: Fix some CodeQL alerts.

pull/8480/head
J0anJosep 2023-08-26 17:49:33 +02:00
parent ced241ed87
commit 224b2343f0
3 changed files with 46 additions and 57 deletions

View File

@ -1659,8 +1659,8 @@ CommandCost CmdConvertRail(DoCommandFlag flags, TileIndex tile, TileIndex area_s
switch (tt) {
case MP_RAILWAY:
switch (GetRailTileType(tile)) {
case RAIL_TILE_DEPOT:
found_convertible_track = true;
if (GetRailTileType(tile) == RAIL_TILE_DEPOT) {
if (flags & DC_EXEC) {
/* notify YAPF about the track layout change */
YapfNotifyTrackLayoutChange(tile, GetRailDepotTrack(tile));
@ -1669,12 +1669,8 @@ CommandCost CmdConvertRail(DoCommandFlag flags, TileIndex tile, TileIndex area_s
affected_depots.push_back(GetDepotIndex(tile));
}
}
found_convertible_track = true;
cost.AddCost(RailConvertCost(type, totype));
break;
default: // RAIL_TILE_NORMAL, RAIL_TILE_SIGNALS
} else { // RAIL_TILE_NORMAL, RAIL_TILE_SIGNALS
if (flags & DC_EXEC) {
/* notify YAPF about the track layout change */
TrackBits tracks = GetTrackBits(tile);
@ -1682,9 +1678,7 @@ CommandCost CmdConvertRail(DoCommandFlag flags, TileIndex tile, TileIndex area_s
YapfNotifyTrackLayoutChange(tile, RemoveFirstTrack(&tracks));
}
}
found_convertible_track = true;
cost.AddCost(RailConvertCost(type, totype) * CountBits(GetTrackBits(tile)));
break;
}
break;

View File

@ -2270,9 +2270,7 @@ static const uint8_t _roadveh_enter_depot_dir[4] = {
static VehicleEnterTileStatus VehicleEnter_Road(Vehicle *v, TileIndex tile, int, int)
{
switch (GetRoadTileType(tile)) {
case ROAD_TILE_DEPOT: {
if (v->type != VEH_ROAD) break;
if (GetRoadTileType(tile) != ROAD_TILE_DEPOT || v->type != VEH_ROAD) return VETSB_CONTINUE;
RoadVehicle *rv = RoadVehicle::From(v);
if (rv->frame == RVC_DEPOT_STOP_FRAME &&
@ -2286,11 +2284,7 @@ static VehicleEnterTileStatus VehicleEnter_Road(Vehicle *v, TileIndex tile, int,
InvalidateWindowData(WC_VEHICLE_DEPOT, GetDepotIndex(rv->tile));
return VETSB_ENTERED_WORMHOLE;
}
break;
}
default: break;
}
return VETSB_CONTINUE;
}

View File

@ -654,30 +654,31 @@ struct RoadVehFindData {
static Vehicle *EnumCheckRoadVehClose(Vehicle *v, void *data)
{
static const int8_t dist_x[] = { -4, -8, -4, -1, 4, 8, 4, 1 };
static const int8_t dist_y[] = { -4, -1, 4, 8, 4, 1, -4, -8 };
if (v->type != VEH_ROAD || v->IsInDepot()) return nullptr;
RoadVehFindData *rvf = (RoadVehFindData*)data;
if (abs(v->z_pos - rvf->veh->z_pos) >= 6 ||
v->direction != rvf->dir ||
rvf->veh->First() == v->First()) return nullptr;
static const int8_t dist_x[] = { -4, -8, -4, -1, 4, 8, 4, 1 };
static const int8_t dist_y[] = { -4, -1, 4, 8, 4, 1, -4, -8 };
short x_diff = v->x_pos - rvf->x;
short y_diff = v->y_pos - rvf->y;
if (v->type == VEH_ROAD &&
!v->IsInDepot() &&
abs(v->z_pos - rvf->veh->z_pos) < 6 &&
v->direction == rvf->dir &&
rvf->veh->First() != v->First() &&
(dist_x[v->direction] >= 0 || (x_diff > dist_x[v->direction] && x_diff <= 0)) &&
(dist_x[v->direction] <= 0 || (x_diff < dist_x[v->direction] && x_diff >= 0)) &&
(dist_y[v->direction] >= 0 || (y_diff > dist_y[v->direction] && y_diff <= 0)) &&
(dist_y[v->direction] <= 0 || (y_diff < dist_y[v->direction] && y_diff >= 0))) {
/* Check if vehicle is not close. */
if ((dist_x[v->direction] < 0 && (x_diff > 0 || x_diff <= dist_x[v->direction]))) return nullptr;
if ((dist_x[v->direction] > 0 && (x_diff < 0 || x_diff >= dist_x[v->direction]))) return nullptr;
if ((dist_y[v->direction] < 0 && (y_diff > 0 || y_diff <= dist_y[v->direction]))) return nullptr;
if ((dist_y[v->direction] > 0 && (y_diff < 0 || y_diff >= dist_y[v->direction]))) return nullptr;
uint diff = abs(x_diff) + abs(y_diff);
if (diff < rvf->best_diff || (diff == rvf->best_diff && v->index < rvf->best->index)) {
rvf->best = v;
rvf->best_diff = diff;
}
}
return nullptr;
}