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

Add check rcl_node_options_copy invalid out #671

Merged
merged 5 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rcl/src/rcl/node_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ rcl_node_options_copy(
RCL_SET_ERROR_MSG("Attempted to copy options into itself");
return RCL_RET_INVALID_ARGUMENT;
}
if (NULL != options_out->arguments.impl) {
Blast545 marked this conversation as resolved.
Show resolved Hide resolved
RCL_SET_ERROR_MSG("Options out must be zero initialized");
return RCL_RET_INVALID_ARGUMENT;
}
options_out->domain_id = options->domain_id;
options_out->allocator = options->allocator;
options_out->use_global_arguments = options->use_global_arguments;
Expand Down
13 changes: 7 additions & 6 deletions rcl/test/rcl/test_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,11 +784,12 @@ TEST_F(CLASSNAME(TestNodeFixture, RMW_IMPLEMENTATION), test_rcl_node_options) {
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_node_options_fini(nullptr));
EXPECT_EQ(RCL_RET_OK, rcl_node_options_fini(&default_options));
EXPECT_EQ(RCL_RET_OK, rcl_node_options_fini(&not_ini_options));
}

// (TODO: blast545) will be fixed with: https://github.com/ros2/rcl/pull/671
// This causes the test suite to fail:
// rcl_node_options_t default_options = rcl_node_get_default_options();
// rcl_node_options_t not_ini_options;
// EXPECT_EQ(RCL_RET_OK, rcl_node_options_copy(&default_options, &not_ini_options));
// EXPECT_EQ(RCL_RET_OK, rcl_node_options_fini(&not_ini_options)); <-- code fails, returns -11
/* Tests special case node_options
*/
TEST_F(CLASSNAME(TestNodeFixture, RMW_IMPLEMENTATION), test_rcl_node_options_fail) {
rcl_node_options_t not_ini_options;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since not_ini_options is uninitialized there is a possibility that the impl pointer could be 0 in some runs, so you might be better off explicitly setting it to a non-null value for this test.

Copy link
Contributor

Choose a reason for hiding this comment

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

Precisely this @Blast545, not a good idea to use an uninitialized variable.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is why windows failed. It probably had not_ini_options.impl as NULL, either randomly or intentionally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hidmic I agree that's a bad idea to leave not_ini_options uninitialized before calling the copy method. Just checked the docblock in the header and already says that the destination has to be initialized, so I can reformat the test.

@brawner @hidmic However, this PR is catching a failure for the "not init" scenario, which means that if the variable is init this check won't be catched for Line Coverage. Any Ideas how should I proceed?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think all you need to do is assign a pointer to not_ini_options.impl to catch the expected failure on copy.

rcl_node_options_t default_options = rcl_node_get_default_options();
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_node_options_copy(&default_options, &not_ini_options));
}