aboutsummaryrefslogtreecommitdiff
path: root/src/common/address.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-09-15 13:52:13 -0400
committerNick Mathewson <nickm@torproject.org>2014-09-15 13:52:13 -0400
commit53a94c4b4bf2e75ec4c9132c91cf70ca4520bd1c (patch)
tree99a44d5a374afc0747138d353c32872fd5979460 /src/common/address.h
parentd6b2a1709d28c656dadc019fb24145e6ac400771 (diff)
downloadtor-53a94c4b4bf2e75ec4c9132c91cf70ca4520bd1c.tar.gz
tor-53a94c4b4bf2e75ec4c9132c91cf70ca4520bd1c.zip
Clear up another clangalyzer issue
"The NULL pointer warnings on the return value of tor_addr_to_in6_addr32() are incorrect. But clang can't work this out itself due to limited analysis depth. To teach the analyser that the return value is safe to dereference, I applied tor_assert to the return value." Patch from teor. Part of 13157.
Diffstat (limited to 'src/common/address.h')
-rw-r--r--src/common/address.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/common/address.h b/src/common/address.h
index 8dc63b71c1..42844e8ad1 100644
--- a/src/common/address.h
+++ b/src/common/address.h
@@ -103,7 +103,18 @@ tor_addr_to_ipv4h(const tor_addr_t *a)
static INLINE uint32_t
tor_addr_to_mapped_ipv4h(const tor_addr_t *a)
{
- return a->family == AF_INET6 ? ntohl(tor_addr_to_in6_addr32(a)[3]) : 0;
+ if (a->family == AF_INET6) {
+ uint32_t *addr32 = NULL;
+ // Work around an incorrect NULL pointer dereference warning in
+ // "clang --analyze" due to limited analysis depth
+ addr32 = tor_addr_to_in6_addr32(a);
+ // To improve performance, wrap this assertion in:
+ // #if !defined(__clang_analyzer__) || PARANOIA
+ tor_assert(addr32);
+ return ntohl(addr32[3]);
+ } else {
+ return 0;
+ }
}
/** Return the address family of <b>a</b>. Possible values are:
* AF_INET6, AF_INET, AF_UNSPEC. */