Skip to content

5 digit port numbers are truncated #314

@jimmy-mcelwain

Description

@jimmy-mcelwain

Context Yaskawa-Global/motoros2#376

Describe the bug
If a 5 digit port number is specified, the last digit gets cut off.

To Reproduce
Specify a 5 digit port number. If I choose 16510, then the "real" port number ends up being 1651.

Expected behaviour
If I specify a 5 digit port number, the last digit should not be truncated. It should alarm for 0 or 6+ digits.

System information (please complete the following information):

  • Found on a YRC1000. Client PC is running micro-ros agent.
  • Found on ROS2 Jazzy
  • 5.01

Additional context

The problem lies here:

if (port != NULL && strlen(port) <= MAX_PORT_LEN) {
snprintf(rmw_options->impl->transport_params.agent_port, MAX_PORT_LEN, "%s", port);
} else {
RMW_UROS_TRACE_MESSAGE("default port configuration error")
return RMW_RET_INVALID_ARGUMENT;
}

With the maximum length argument in snprintf being MAX_PORT_LENGTH, that means that at most MAX_PORT_LENGTH - 1 characters will be copied into the agent_port array, since it needs room to put the terminating \0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions