Skip to content

Commit

Permalink
log: net: Fix build warning with IPv6 disabled
Browse files Browse the repository at this point in the history
Building the net logger backend with IPv4 only gives the following
warning:

log_backend_net.c:116:31: warning: array subscript 'struct sockaddr[0]'
is partly outside array bounds of 'struct sockaddr_in[1]'
[-Warray-bounds] local_addr->sa_family = server_addr.sa_family;

hence assign the address family directly to sockaddr_in/6 structs.

Signed-off-by: Robert Lubos <[email protected]>
  • Loading branch information
rlubos committed Oct 4, 2024
1 parent 939423b commit a58ade1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions subsys/logging/backends/log_backend_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@ static int do_net_init(struct log_backend_net_ctx *ctx)
if (IS_ENABLED(CONFIG_NET_IPV4) && server_addr.sa_family == AF_INET) {
local_addr = (struct sockaddr *)&local_addr4;
server_addr_len = sizeof(struct sockaddr_in);
local_addr4.sin_family = AF_INET;
local_addr4.sin_port = 0U;
}

if (IS_ENABLED(CONFIG_NET_IPV6) && server_addr.sa_family == AF_INET6) {
local_addr = (struct sockaddr *)&local_addr6;
server_addr_len = sizeof(struct sockaddr_in6);
local_addr6.sin6_family = AF_INET6;
local_addr6.sin6_port = 0U;
}

Expand All @@ -113,8 +115,6 @@ static int do_net_init(struct log_backend_net_ctx *ctx)
return -EINVAL;
}

local_addr->sa_family = server_addr.sa_family;

if (ctx->is_tcp) {
proto = IPPROTO_TCP;
type = SOCK_STREAM;
Expand Down

0 comments on commit a58ade1

Please sign in to comment.