Skip to content

Commit 6fb3473

Browse files
jukkarmmahadevan108
authored andcommitted
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: Jukka Rissanen <[email protected]>
1 parent b29534f commit 6fb3473

File tree

1 file changed

+3
-3
lines changed
  • samples/net/sockets/echo_server/src

1 file changed

+3
-3
lines changed

samples/net/sockets/echo_server/src/tcp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ static int process_tcp(struct data *data)
250250

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

253-
#define MAX_NAME_LEN sizeof("tcp6[0]")
253+
#define MAX_NAME_LEN sizeof("tcp6[xxx]")
254254

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

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

297-
snprintk(name, sizeof(name), "tcp4[%d]", slot);
297+
snprintk(name, sizeof(name), "tcp4[%3d]", (uint8_t)slot);
298298
k_thread_name_set(&tcp4_handler_thread[slot], name);
299299
}
300300
}

0 commit comments

Comments
 (0)