Skip to content

Commit 498773b

Browse files
authored
Minor check on snprintf (#195)
1 parent db118f1 commit 498773b

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

rmw_microxrcedds_c/src/rmw_microros/discovery.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,18 @@ bool on_agent_found(
3434
uint16_t port;
3535

3636
uxr_locator_to_ip(locator, ip, sizeof(ip), &port, &ip_protocol);
37-
snprintf(port_str, MAX_PORT_LEN, "%d", port);
37+
if (0 > snprintf(port_str, MAX_PORT_LEN, "%d", port)) {
38+
return false;
39+
}
3840

3941
uxrUDPTransport transport;
4042
if (uxr_init_udp_transport(&transport, ip_protocol, ip, port_str)) {
4143
uxrSession session;
4244
uxr_init_session(&session, &transport.comm, rmw_options->impl->transport_params.client_key);
4345
if (uxr_create_session_retries(&session, 5)) {
44-
snprintf(rmw_options->impl->transport_params.agent_port, MAX_PORT_LEN, "%d", port);
46+
if (0 > snprintf(rmw_options->impl->transport_params.agent_port, MAX_PORT_LEN, "%d", port)) {
47+
return false;
48+
}
4549
snprintf(rmw_options->impl->transport_params.agent_address, MAX_IP_LEN, "%s", ip);
4650
uxr_delete_session(&session);
4751
return true;

0 commit comments

Comments
 (0)