Skip to content

Commit 9e85669

Browse files
thugheskartben
authored andcommitted
tests: net: socket: Fix -Wsometimes-uninitialized warning
Building with clang warns: tests/net/socket/tcp/src/main.c:377:13: error: variable 'c_sock' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] } else if (family == AF_INET6) { ^~~~~~~~~~~~~~~~~~ tests/net/socket/tcp/src/main.c:396:15: note: uninitialized use occurs here test_connect(c_sock, s_saddr, addrlen); ^~~~~~ tests/net/socket/tcp/src/main.c:377:9: note: remove the 'if' if its condition is always true } else if (family == AF_INET6) { ^~~~~~~~~~~~~~~~~~~~~~~~ tests/net/socket/tcp/src/main.c:360:12: note: initialize the variable 'c_sock' to silence this warning int c_sock; ^ = 0 tests/net/socket/tcp/src/main.c:377:13: error: variable 's_sock' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] } else if (family == AF_INET6) { ^~~~~~~~~~~~~~~~~~ tests/net/socket/tcp/src/main.c:387:12: note: uninitialized use occurs here test_bind(s_sock, s_saddr, addrlen); ^~~~~~ tests/net/socket/tcp/src/main.c:377:9: note: remove the 'if' if its condition is always true } else if (family == AF_INET6) { ^~~~~~~~~~~~~~~~~~~~~~~~ tests/net/socket/tcp/src/main.c:361:12: note: initialize the variable 's_sock' to silence this warning int s_sock; ^ = 0 Not really needed since we have zassert_unreachable(), but doesn't hurt to initialize the variables. Signed-off-by: Tom Hughes <[email protected]>
1 parent 57f3884 commit 9e85669

File tree

1 file changed

+2
-2
lines changed
  • tests/net/socket/tcp/src

1 file changed

+2
-2
lines changed

tests/net/socket/tcp/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ void tcp_server_block_thread(void *vps_sock, void *unused2, void *unused3)
357357
void test_send_recv_large_common(int tcp_nodelay, int family)
358358
{
359359
int rv;
360-
int c_sock;
361-
int s_sock;
360+
int c_sock = 0;
361+
int s_sock = 0;
362362
struct sockaddr *c_saddr = NULL;
363363
struct sockaddr *s_saddr = NULL;
364364
size_t addrlen = 0;

0 commit comments

Comments
 (0)