-
Notifications
You must be signed in to change notification settings - Fork 33
Description
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:
rmw_microxrcedds/rmw_microxrcedds_c/src/rmw_microros/init_options.c
Lines 100 to 105 in 554445f
| 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.