Skip to content

Commit

Permalink
Fix division by 0 width in PointCloud structured assign (#5113)
Browse files Browse the repository at this point in the history
* Check for width in assign().

* Update common/include/pcl/point_cloud.h

Co-authored-by: Markus Vieth <39675748+mvieth@users.noreply.github.com>

Co-authored-by: Markus Vieth <39675748+mvieth@users.noreply.github.com>
  • Loading branch information
vcarpani and mvieth authored Jan 2, 2022
1 parent fac4b27 commit c1835f4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions common/include/pcl/point_cloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,12 @@ namespace pcl
inline void
assign(InputIterator first, InputIterator last, index_t new_width)
{
if (new_width == 0) {
PCL_WARN("Assignment with new_width equal to 0,"
"setting width to size of the cloud and height to 1\n");
return assign(std::move(first), std::move(last));
}

points.assign(std::move(first), std::move(last));
width = new_width;
height = size() / width;
Expand Down Expand Up @@ -631,6 +637,11 @@ namespace pcl
void
inline assign(std::initializer_list<PointT> ilist, index_t new_width)
{
if (new_width == 0) {
PCL_WARN("Assignment with new_width equal to 0,"
"setting width to size of the cloud and height to 1\n");
return assign(std::move(ilist));
}
points.assign(std::move(ilist));
width = new_width;
height = size() / width;
Expand Down

0 comments on commit c1835f4

Please sign in to comment.