Repository navigation
Fix use of uninitialized memory in simple_tf2_core tests. #18
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,31 +34,22 @@ | |
| #include "tf2/exceptions.h" | ||
| #include "tf2/time.h" | ||
|
|
||
| typedef std::chrono::system_clock::time_point TimePoint; | ||
|
|
||
| void seed_rand() | ||
| { | ||
| //Seed random number generator with current microseond count | ||
| srand((unsigned int)std::chrono::system_clock::now().time_since_epoch().count()); | ||
| }; | ||
|
|
||
| void generate_rand_vectors(double scale, uint64_t runs, std::vector<double>& xvalues, std::vector<double>& yvalues, std::vector<double>&zvalues) | ||
| { | ||
| seed_rand(); | ||
| for ( uint64_t i = 0; i < runs ; i++ ) | ||
| { | ||
| xvalues[i] = 1.0 * ((double) rand() - (double)RAND_MAX /2.0) /(double)RAND_MAX; | ||
| yvalues[i] = 1.0 * ((double) rand() - (double)RAND_MAX /2.0) /(double)RAND_MAX; | ||
| zvalues[i] = 1.0 * ((double) rand() - (double)RAND_MAX /2.0) /(double)RAND_MAX; | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| TEST(tf2, setTransformFail) | ||
| { | ||
| tf2::BufferCore tfc; | ||
| geometry_msgs::msg::TransformStamped st; | ||
| st.header.frame_id = "foo"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test was relying on 'bad' values. Here's the output of an upstream job (http://build.ros.org/job/Ipr__geometry2__ubuntu_trusty_amd64/83/consoleFull search for setTransformFail): But the output of the CI for this job:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, will fix.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, I'll use the 'request changes' button from now on so comments don't get buried accidentally
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| st.header.stamp = builtin_interfaces::msg::Time(); | ||
| st.header.stamp.sec = 1; | ||
| st.header.stamp.nanosec = 1; | ||
| st.child_frame_id = "foo"; | ||
| st.transform.translation.x = 0; | ||
| st.transform.translation.y = 0; | ||
| st.transform.translation.z = 0; | ||
| st.transform.rotation.x = 0; | ||
| st.transform.rotation.y = 0; | ||
| st.transform.rotation.z = 0; | ||
| st.transform.rotation.w = 1; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you provide an example / test showing that they're not initialized? If they're not initialized it should be fixed in the message generation and not in the test of a leaf package.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, we should probably have a conversation about this. This is the second time I've had to do something like this in a test (I can't remember where the other one was, but I can dig it up). What's going on here is that a declaration like: geometry_msgs::msg::TransformStamped foo; has a constructor that looks like this: TransformStamped_() (from transform_stamped__struct.hpp). As far as I understand, what that means is that that constructor doesn't initialize any member variables. Thus, when you use the object later on, everything is uninitialized. When you run this under valgrind, it throws a slew of errors saying you are making decisions using uninitialized variables, etc. I think you are right, by the way; for the long-term maintenance of this stuff, we should probably do a real constructor for these messages by changing the message generation.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So let's see. I'm discussing this with @dirk-thomas on ros2/rosidl#77 . If we decide to do a default initialization of all fields, then that will take time to implement. If we decide not to do it, then we have to fill in all of the fields. Thus, my feeling is that for the short-term, we should take this code (after review, of course), no matter which way we decide to go. Thoughts?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 sounds good to me |
||
| EXPECT_FALSE(tfc.setTransform(st, "authority1")); | ||
|
|
||
| } | ||
|
|
@@ -89,7 +80,15 @@ TEST(tf2, setTransformInvalidQuaternion) | |
| geometry_msgs::msg::TransformStamped st; | ||
| st.header.frame_id = "foo"; | ||
| st.header.stamp = builtin_interfaces::msg::Time(); | ||
| st.header.stamp.sec = 1; | ||
| st.header.stamp.nanosec = 1; | ||
| st.child_frame_id = "child"; | ||
| st.transform.translation.x = 0; | ||
| st.transform.translation.y = 0; | ||
| st.transform.translation.z = 0; | ||
| st.transform.rotation.x = 0; | ||
| st.transform.rotation.y = 0; | ||
| st.transform.rotation.z = 0; | ||
| st.transform.rotation.w = 0; | ||
| EXPECT_FALSE(tfc.setTransform(st, "authority1")); | ||
|
|
||
|
|
@@ -98,14 +97,14 @@ TEST(tf2, setTransformInvalidQuaternion) | |
| TEST(tf2_lookupTransform, LookupException_Nothing_Exists) | ||
| { | ||
| tf2::BufferCore tfc; | ||
| EXPECT_THROW(tfc.lookupTransform("a", "b", TimePoint(std::chrono::seconds(1))), tf2::LookupException); | ||
| EXPECT_THROW(tfc.lookupTransform("a", "b", tf2::TimePoint(std::chrono::seconds(1))), tf2::LookupException); | ||
|
|
||
| } | ||
|
|
||
| TEST(tf2_canTransform, Nothing_Exists) | ||
| { | ||
| tf2::BufferCore tfc; | ||
| EXPECT_FALSE(tfc.canTransform("a", "b", TimePoint(std::chrono::seconds(1)))); | ||
| EXPECT_FALSE(tfc.canTransform("a", "b", tf2::TimePoint(std::chrono::seconds(1)))); | ||
|
|
||
| } | ||
|
|
||
|
|
@@ -126,7 +125,7 @@ TEST(tf2_lookupTransform, LookupException_One_Exists) | |
| st.transform.rotation.z = 0; | ||
| st.transform.rotation.w = 1; | ||
| EXPECT_TRUE(tfc.setTransform(st, "authority1")); | ||
| EXPECT_THROW(tfc.lookupTransform("foo", "bar", TimePoint(std::chrono::seconds(1))), tf2::LookupException); | ||
| EXPECT_THROW(tfc.lookupTransform("foo", "bar", tf2::TimePoint(std::chrono::seconds(1))), tf2::LookupException); | ||
|
|
||
| } | ||
|
|
||
|
|
@@ -147,7 +146,7 @@ TEST(tf2_canTransform, One_Exists) | |
| st.transform.rotation.z = 0; | ||
| st.transform.rotation.w = 1; | ||
| EXPECT_TRUE(tfc.setTransform(st, "authority1")); | ||
| EXPECT_FALSE(tfc.canTransform("foo", "bar", TimePoint(std::chrono::seconds(1)))); | ||
| EXPECT_FALSE(tfc.canTransform("foo", "bar", tf2::TimePoint(std::chrono::seconds(1)))); | ||
| } | ||
|
|
||
| TEST(tf2_time, Display_Time_Point) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that related to uninitialized messages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, not directly. It just wasn't used. This is a piece that can go upstream as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in that case can you make this in separate commits in the future. This way you can submit the same commit upstream.