Skip to content

Commit 39d8c46

Browse files
authored
fix(autoware_utils_geometry): add optional check (#89)
fix(autoware_utils_geometry): add optional check before accessing value in triangulate Add a check for empty optional before calling .value() on alt_poly. If alt::Polygon2d::create() returns std::nullopt (e.g., for polygons with less than 4 points), the function now returns an empty vector instead of throwing std::bad_optional_access. Detected by Facebook Infer static analyzer (OPTIONAL_EMPTY_ACCESS). Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp>
1 parent c75228a commit 39d8c46

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

autoware_utils_geometry/src/geometry/ear_clipping.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,10 @@ std::vector<alt::ConvexPolygon2d> triangulate(const alt::Polygon2d & poly)
624624
std::vector<Polygon2d> triangulate(const Polygon2d & poly)
625625
{
626626
const auto alt_poly = alt::Polygon2d::create(poly);
627+
if (!alt_poly) {
628+
return {};
629+
}
630+
627631
const auto alt_triangles = triangulate(alt_poly.value());
628632
std::vector<Polygon2d> triangles;
629633
for (const auto & alt_triangle : alt_triangles) {

0 commit comments

Comments
 (0)