Skip to content

Commit

Permalink
Use rmw_validate_node_name_with_size
Browse files Browse the repository at this point in the history
  • Loading branch information
sloretz committed Mar 15, 2018
1 parent c04c2eb commit 1925221
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions rcl/src/rcl/arguments.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ extern "C"
// Instance of global arguments.
static rcl_arguments_t __rcl_global_arguments;

/// Return true if c is in [a-zA-Z0-9_].
/// \internal
RCL_LOCAL
bool
_rcl_valid_token_char(char c)
{
// assumes ASCII
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
}

/// Parse an argument that may or may not be a remap rule.
/// \param[in] arg the argument to parse
/// \param[in] allocator an allocator to use
Expand Down Expand Up @@ -114,11 +104,19 @@ _rcl_parse_remap_rule(
return RCL_RET_INVALID_REMAP_RULE;
}

// TODO(sloretz) rmw_validate_node_name with size
// Make sure node name contains only valid characters
for (size_t i = 0; i < len_node_name; ++i) {
if (!_rcl_valid_token_char(arg[i])) {
RCL_SET_ERROR_MSG("Node name prefix has invalid characters", allocator);
if (len_node_name) {
int validation_result;
size_t invalid_index;
if (
RMW_RET_OK != rmw_validate_node_name_with_size(arg, len_node_name, &validation_result,
&invalid_index))

This comment has been minimized.

Copy link
@wjwwood

wjwwood Mar 16, 2018

Member

Suggestion: do something like this:

rmw_ret_t rmw_ret = rmw_validate_node_name_with_size(
  arg, len_node_name, &validation_result, &invalid_index);
if (RMW_RET_OK != rmw_ret) {
....

This comment has been minimized.

Copy link
@sloretz

sloretz Mar 16, 2018

Author Contributor

Your version looks much better. I'll put that in a follow-up PR

Edit: PR #221

{
RCL_SET_ERROR_MSG("failed to run check on node name", allocator);
return RCL_RET_ERROR;
}
if (RMW_NODE_NAME_VALID != validation_result) {
RCL_SET_ERROR_MSG("node name prefix is not a valid node name", allocator);
return RCL_RET_INVALID_REMAP_RULE;
}
}
Expand Down

0 comments on commit 1925221

Please sign in to comment.