Commit 6fb34733 authored by Jukka Rissanen's avatar Jukka Rissanen Committed by Mahesh Mahadevan
Browse files

samples: net: echo_server: Avoid warning about truncated writing



The truncation is not possible in practice but add suitable cast to
avoid the warning.

samples/net/sockets/echo_server/src/tcp.c:297:54: warning:
 ‘%d’ directive output may be truncated writing between 1 and 10 bytes
 into a region of size 5 [-Wformat-truncation=]
  297 |               snprintk(name, sizeof(name), "tcp4[%d]", slot);
      |                                             ^~~~~~~~~~

Signed-off-by: default avatarJukka Rissanen <jukka.rissanen@nordicsemi.no>
parent b29534f0
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -250,7 +250,7 @@ static int process_tcp(struct data *data)

	LOG_INF("TCP (%s): Accepted connection", data->proto);

#define MAX_NAME_LEN sizeof("tcp6[0]")
#define MAX_NAME_LEN sizeof("tcp6[xxx]")

#if defined(CONFIG_NET_IPV6)
	if (client_addr.sin_family == AF_INET6) {
@@ -270,7 +270,7 @@ static int process_tcp(struct data *data)
		if (IS_ENABLED(CONFIG_THREAD_NAME)) {
			char name[MAX_NAME_LEN];

			snprintk(name, sizeof(name), "tcp6[%d]", slot);
			snprintk(name, sizeof(name), "tcp6[%3d]", (uint8_t)slot);
			k_thread_name_set(&tcp6_handler_thread[slot], name);
		}
	}
@@ -294,7 +294,7 @@ static int process_tcp(struct data *data)
		if (IS_ENABLED(CONFIG_THREAD_NAME)) {
			char name[MAX_NAME_LEN];

			snprintk(name, sizeof(name), "tcp4[%d]", slot);
			snprintk(name, sizeof(name), "tcp4[%3d]", (uint8_t)slot);
			k_thread_name_set(&tcp4_handler_thread[slot], name);
		}
	}