Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/segfault when getting surrounding interval of empty cache #116

Conversation

Cakem1x
Copy link
Contributor

@Cakem1x Cakem1x commented Mar 12, 2024

This PR fixes a segfault that occurred to me when I tried to get a surrounding interval from a message_filter::Cache that was empty. See comment below for where/how.

The PR includes

  • a test that should reproduce the segfault when executed without the fix.
  • the fix of the segfault

Is it possible to get the fix also to other branches, specifically humble (but iron would probably also make sense)? That's the version I am using at the moment. I think the fix commit should be cherry-pickable. But the test commit probably needs some minor adaptation due to namespace changes.

Please let me know if I need to follow some specific procedure or provide more information for contributing (e.g. create issue first, or similar).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

segfault occurs in line 229/235, when cache size is empty.
start_index and end_index are both -1, the current logic will then reserve -1 - (-1) + 1 = 1 element and try to push_back(cache_[-1]...);.

@Cakem1x Cakem1x marked this pull request as ready for review March 12, 2024 15:29
@Cakem1x Cakem1x requested a review from gbiggs as a code owner March 12, 2024 15:29
Copy link
Contributor

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

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

Do you mind to fix the conflicts ?

TEST(Cache, emptySurroundingInterval)
{
message_filters::Cache<Msg> cache(10);
const std::vector<std::shared_ptr<Msg const> > interval_data = cache.getSurroundingInterval(rclcpp::Time(5, 0), rclcpp::Time(9, 0));
Copy link
Contributor

Choose a reason for hiding this comment

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

line too long, it should be less than 100 characters

@Cakem1x Cakem1x force-pushed the bugfix/segfault-when-getting-surrounding-interval-of-empty-cache branch from 1c9b0f5 to d89350d Compare July 31, 2024 11:31
fixes segfault in Cache::getSurroundingInterval
@Cakem1x Cakem1x force-pushed the bugfix/segfault-when-getting-surrounding-interval-of-empty-cache branch from d89350d to dd5bb14 Compare July 31, 2024 11:37
Copy link
Contributor

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

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

@Cakem1x
Copy link
Contributor Author

Cakem1x commented Jul 31, 2024

Still some linters failures https://build.ros2.org/job/Rpr__message_filters__ubuntu_noble_amd64/87/#showFailuresLink

Right, sorry, I had some issues with my local ament_uncrustify installation and tried to doctor the codestyle for this PR manually. Looks like codestyling is not a job for humans ;)
Fixing ament_uncrustify was worth it! Hope your CI's linter agrees with my local linter.

@Cakem1x
Copy link
Contributor Author

Cakem1x commented Jul 31, 2024

Just out of curiosity, do you use some specific tool (via IDE or CLI) to automatically format code to your CI's liking? ament_uncrustify has this nice --reformat option, but apparently some things are only caught by cpplint. And ament_cpplint can only complain, not fix.

@Cakem1x Cakem1x requested a review from ahcorde July 31, 2024 13:49
Comment on lines 82 to 85
rclcpp::Time(
5,
0), rclcpp::Time(
9, 0));
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation looks odd. Did you try something like this ?

Suggested change
rclcpp::Time(
5,
0), rclcpp::Time(
9, 0));
rclcpp::Time(5, 0), rclcpp::Time(9, 0));

0), rclcpp::Time(
9, 0));

EXPECT_EQ(interval_data.size(), (unsigned int) 0); // empty cache shall return empty interval
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
EXPECT_EQ(interval_data.size(), (unsigned int) 0); // empty cache shall return empty interval
EXPECT_EQ(interval_data.size(), static_cast<unsigned int>(0)); // empty cache shall return empty interval

@Cakem1x
Copy link
Contributor Author

Cakem1x commented Aug 1, 2024

Looks like something is up with Jenkins, could you please re-trigger the job (when Jenkins is feeling better)? I think the failure is unrelated to the changes in this PR.

@ahcorde
Copy link
Contributor

ahcorde commented Aug 1, 2024

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@clalancette
Copy link
Contributor

@ros-pull-request-builder retest this please

@ahcorde ahcorde merged commit e60450d into ros2:rolling Aug 1, 2024
2 checks passed
@ahcorde
Copy link
Contributor

ahcorde commented Aug 1, 2024

@Cakem1x Thank you for iterating and the contribution

@ahcorde
Copy link
Contributor

ahcorde commented Aug 1, 2024

https://github.com/Mergifyio backport jazzy

Copy link

mergify bot commented Aug 1, 2024

backport jazzy

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Aug 1, 2024
(cherry picked from commit e60450d)

# Conflicts:
#	include/message_filters/cache.hpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants