Skip to content

Commit 03773a3

Browse files
author
随风而散
committed
fix bug heap-buffer-overflow
1 parent c41f69b commit 03773a3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

nav2_costmap_2d/src/costmap_2d.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,15 @@ bool Costmap2D::setConvexPolygonCost(
350350
convexFillCells(map_polygon, polygon_cells);
351351

352352
// set the cost of those cells
353+
bool cells_written = false;
353354
for (unsigned int i = 0; i < polygon_cells.size(); ++i) {
354355
unsigned int index = getIndex(polygon_cells[i].x, polygon_cells[i].y);
355-
costmap_[index] = cost_value;
356+
if (index < size_x_ * size_y_) {
357+
costmap_[index] = cost_value;
358+
cells_written = true;
359+
}
356360
}
357-
return true;
361+
return cells_written;
358362
}
359363

360364
void Costmap2D::polygonOutlineCells(

0 commit comments

Comments
 (0)