1
0
Fork 0

Fix f214c81e97: Signed overflow in collision test on large map when road vehicles are at just the right coordinates. (#13847)

If road vehicles are -32768 subtiles apart, the distance check will break.
pull/13850/head
Peter Nelson 2025-03-18 22:53:01 +00:00 committed by GitHub
parent 8e2ce35143
commit b98a7ff303
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 3 deletions

View File

@ -617,8 +617,8 @@ static Vehicle *EnumCheckRoadVehClose(Vehicle *v, void *data)
RoadVehFindData *rvf = (RoadVehFindData*)data;
short x_diff = v->x_pos - rvf->x;
short y_diff = v->y_pos - rvf->y;
int x_diff = v->x_pos - rvf->x;
int y_diff = v->y_pos - rvf->y;
/* Not a close Road vehicle when it's not a road vehicle, in the depot, or ourself. */
if (v->type != VEH_ROAD || v->IsInDepot() || rvf->veh->First() == v->First()) return nullptr;
@ -630,7 +630,7 @@ static Vehicle *EnumCheckRoadVehClose(Vehicle *v, void *data)
uint diff = abs(x_diff) + abs(y_diff);
if (diff > rvf->best_diff || (diff == rvf->best_diff && v->index > rvf->best->index)) return nullptr;
auto IsCloseOnAxis = [](short dist, short diff) {
auto IsCloseOnAxis = [](int dist, int diff) {
if (dist < 0) return diff > dist && diff <= 0;
return diff < dist && diff >= 0;
};