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 NULL check in remap.c #879

Merged
merged 4 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion rcl/src/rcl/remap.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ rcl_remap_first_match(
}
continue;
}
matched = (0 == strcmp(expanded_match, name));
if (NULL != name) {
// this check is to satisfy clang-tidy – name is always not null when type_bitmask is
// RCL_TOPIC_REMAP or RCL_SERVICE_REMAP. That is guaranteed because rcl_remap_first_match
// and rcl_remap_name are not public.
matched = (0 == strcmp(expanded_match, name));
}
allocator.deallocate(expanded_match, allocator.state);
} else {
// nodename and namespace replacement apply if the type and node name prefix checks passed
Expand Down
21 changes: 21 additions & 0 deletions rcl/test/rcl/test_remap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,27 @@ TEST_F(CLASSNAME(TestRemapFixture, RMW_IMPLEMENTATION), global_topic_name_replac
}
}

TEST_F(CLASSNAME(TestRemapFixture, RMW_IMPLEMENTATION), topic_and_service_name_not_null) {
rcl_ret_t ret;
rcl_arguments_t global_arguments;
SCOPE_ARGS(global_arguments, "process_name", "--ros-args", "-r", "/bar/foo:=/foo/bar");

{
char * output = NULL;
ret = rcl_remap_service_name(
NULL, &global_arguments, NULL, "NodeName", "/", rcl_get_default_allocator(), &output);
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret);
ASSERT_EQ(NULL, output);
}
{
char * output = NULL;
ret = rcl_remap_topic_name(
NULL, &global_arguments, NULL, "NodeName", "/", rcl_get_default_allocator(), &output);
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret);
EXPECT_EQ(NULL, output);
}
}

TEST_F(CLASSNAME(TestRemapFixture, RMW_IMPLEMENTATION), relative_topic_name_remap) {
rcl_ret_t ret;
rcl_arguments_t global_arguments;
Expand Down