From f554d6376f3b0c5551fde24dafbb9a9efdd853eb Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 12 Sep 2019 09:46:36 +0930 Subject: [PATCH] wireaddr: handle case where non-IPv6 and non-IPv4 address is returned. Thanks clang! Here's the error: ommon/wireaddr.c:359:14: error: variable 'addr' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] } else if (addrinfo->ai_family == AF_INET6) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ common/wireaddr.c:364:25: note: uninitialized use occurs here tal_arr_expand(addrs, addr); ^~~~ ./common/utils.h:27:16: note: expanded from macro 'tal_arr_expand' (*(p))[n] = (s); \ ^ common/wireaddr.c:359:10: note: remove the 'if' if its condition is always true } else if (addrinfo->ai_family == AF_INET6) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ common/wireaddr.c:354:3: note: variable 'addr' is declared here struct wireaddr addr; ^ Signed-off-by: Rusty Russell --- common/wireaddr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/wireaddr.c b/common/wireaddr.c index 00b258522..5e87f3b5f 100644 --- a/common/wireaddr.c +++ b/common/wireaddr.c @@ -360,7 +360,9 @@ bool wireaddr_from_hostname(struct wireaddr **addrs, const char *hostname, sa6 = (struct sockaddr_in6 *) addrinfo->ai_addr; wireaddr_from_ipv6(&addr, &sa6->sin6_addr, port); res = true; - } + } else + /* Ignore any other address types. */ + continue; tal_arr_expand(addrs, addr); }