Skip to content

Fix division by 0 width in PointCloud structured assign#5113

Merged
mvieth merged 2 commits intoPointCloudLibrary:masterfrom
fizyr-forks:zero-check
Jan 2, 2022
Merged

Fix division by 0 width in PointCloud structured assign#5113
mvieth merged 2 commits intoPointCloudLibrary:masterfrom
fizyr-forks:zero-check

Conversation

@vcarpani
Copy link
Copy Markdown
Contributor

This PR adds some checks to prevent divisions by zero when using the assign operator

Copy link
Copy Markdown
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about handling the 0 case specifically without throwing?

If use input new_width is 0, we call PCL_WARN and call the assign which doesn't take a user input for width

Comment thread common/include/pcl/point_cloud.h Outdated
{
points.assign(std::move(ilist));
width = new_width;
if (width == 0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this check to the top (in both places) and test new_width instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ;)

Comment thread common/include/pcl/point_cloud.h Outdated
kunaltyagi
kunaltyagi previously approved these changes Dec 31, 2021
larshg
larshg previously approved these changes Dec 31, 2021
Comment thread common/include/pcl/point_cloud.h Outdated
{
if (new_width == 0) {
PCL_WARN("Assignment with new_width equal to 0,"
"setting width to size of the cloud and height to 1");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"setting width to size of the cloud and height to 1");
"setting width to size of the cloud and height to 1\n");

Same below, otherwise looks good

@kunaltyagi kunaltyagi added the changelog: fix Meta-information for changelog generation label Jan 1, 2022
@kunaltyagi kunaltyagi changed the title Check for width in assign(). Fix division by 0 width in PointCloud structured assign Jan 1, 2022
@kunaltyagi kunaltyagi dismissed their stale review January 1, 2022 16:54

Waiting for newline

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

@mvieth mvieth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@mvieth mvieth merged commit c1835f4 into PointCloudLibrary:master Jan 2, 2022
@vcarpani vcarpani deleted the zero-check branch January 2, 2022 16:14
themightyoarfish pushed a commit to themightyoarfish/pcl that referenced this pull request Jan 5, 2022
…udLibrary#5113)

* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: fix Meta-information for changelog generation module: common

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants