From 4f8086fb20e93c477f033f58da17aa31b9c29fd6 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 30 May 2016 11:12:58 -0400 Subject: Enable -Wnull-dereference (GCC >=6.1), and fix the easy cases This warning, IIUC, means that the compiler doesn't like it when it sees a NULL check _after_ we've already dereferenced the variable. In such cases, it considers itself free to eliminate the NULL check. There are a couple of tricky cases: One was the case related to the fact that tor_addr_to_in6() can return NULL if it gets a non-AF_INET6 address. The fix was to create a variant which asserts on the address type, and never returns NULL. --- src/common/address.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/common/address.c') diff --git a/src/common/address.c b/src/common/address.c index a6e0f3f491..759b20a094 100644 --- a/src/common/address.c +++ b/src/common/address.c @@ -131,7 +131,8 @@ tor_addr_to_sockaddr(const tor_addr_t *a, #endif sin6->sin6_family = AF_INET6; sin6->sin6_port = htons(port); - memcpy(&sin6->sin6_addr, tor_addr_to_in6(a), sizeof(struct in6_addr)); + memcpy(&sin6->sin6_addr, tor_addr_to_in6_assert(a), + sizeof(struct in6_addr)); return sizeof(struct sockaddr_in6); } else { return 0; -- cgit v1.2.3-54-g00ecf