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

Clean up rcl_expand_topic_name() implementation. #757

Merged
merged 1 commit into from
Aug 19, 2020
Merged
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
27 changes: 2 additions & 25 deletions rcl/src/rcl/expand_topic_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,7 @@ rcl_expand_topic_name(
rmw_ret = rmw_validate_node_name(node_name, &validation_result, NULL);
if (rmw_ret != RMW_RET_OK) {
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
switch (rmw_ret) {
case RMW_RET_INVALID_ARGUMENT:
return RCL_RET_INVALID_ARGUMENT;
case RMW_RET_ERROR:
// fall through on purpose
default:
return RCL_RET_ERROR;
}
return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret);
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 adds a couple of potential return codes that didn't exist previously (looking at rcl_convert_rmw_ret_to_rcl_ret. I think the header needs to be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, looking at rmw_validate_node_name and rmw_validate_namespace documentation, these can only return RMW_RET_OK, RMW_RET_ERROR, and RMW_RET_INVALID_ARGUMENT. Aren't we covered already?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point. It looks fine then.

}
if (validation_result != RMW_NODE_NAME_VALID) {
RCL_SET_ERROR_MSG("node name is invalid");
Expand All @@ -88,14 +81,7 @@ rcl_expand_topic_name(
rmw_ret = rmw_validate_namespace(node_namespace, &validation_result, NULL);
if (rmw_ret != RMW_RET_OK) {
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
switch (rmw_ret) {
case RMW_RET_INVALID_ARGUMENT:
return RCL_RET_INVALID_ARGUMENT;
case RMW_RET_ERROR:
// fall through on purpose
default:
return RCL_RET_ERROR;
}
return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret);
}
if (validation_result != RMW_NODE_NAME_VALID) {
RCL_SET_ERROR_MSG("node namespace is invalid");
Expand Down Expand Up @@ -220,15 +206,6 @@ rcl_expand_topic_name(
return RCL_RET_BAD_ALLOC;
}
}
// if the original input_topic_name has not yet be copied into new memory, strdup it now
if (!local_output) {
local_output = rcutils_strdup(input_topic_name, allocator);
if (!local_output) {
*output_topic_name = NULL;
RCL_SET_ERROR_MSG("failed to allocate memory for output topic");
return RCL_RET_BAD_ALLOC;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no logical path in this function that can result in the execution of this branch.

// finally store the result in the out pointer and return
*output_topic_name = local_output;
return RCL_RET_OK;
Expand Down