Skip to content

Commit e4f3cd9

Browse files
committed
fix off-by-one error
ref: #5053
1 parent ef3144c commit e4f3cd9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

plugins/pathable.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,18 @@ static bool get_pathability_groups(color_ostream &out, unordered_set<uint16_t> *
173173
static bool get_entry_tiles(unordered_set<df::coord> * entry_tiles, const unordered_set<uint16_t> & depot_pathability_groups) {
174174
auto & edge = plotinfo->map_edge;
175175
size_t num_edge_tiles = edge.surface_x.size();
176-
uint32_t max_x, max_y, max_z;
177-
Maps::getTileSize(max_x, max_y, max_z);
176+
uint32_t count_x, count_y, count_z;
177+
Maps::getTileSize(count_x, count_y, count_z);
178+
if (!count_x || !count_y)
179+
return false;
180+
uint16_t max_x = count_x - 1;
181+
uint16_t max_y = count_y - 1;
178182
bool found = false;
179183
for (size_t idx = 0; idx < num_edge_tiles; ++idx) {
180184
df::coord pos(edge.surface_x[idx], edge.surface_y[idx], edge.surface_z[idx]);
181185
auto wgroup = Maps::getWalkableGroup(pos);
182186
if (depot_pathability_groups.contains(wgroup) &&
183-
(pos.x == 0 || pos.y == 0 || pos.x == (int16_t)max_x || pos.y == (int16_t)max_y)) {
187+
(pos.x == 0 || pos.y == 0 || pos.x == max_x || pos.y == max_y)) {
184188
found = true;
185189
if (!entry_tiles)
186190
break;

0 commit comments

Comments
 (0)