diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-11-27 11:48:54 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-11-27 11:48:54 -0500 |
commit | f108be7c2556de20dc34c0a8ad52b19c363febbd (patch) | |
tree | 6cdc31e58beeeac45033db7b34a43a5fa3605ad0 /src/common/compat.c | |
parent | a45aacd2e292ea0522313e430e5ff8c70fadf8f7 (diff) | |
download | tor-f108be7c2556de20dc34c0a8ad52b19c363febbd.tar.gz tor-f108be7c2556de20dc34c0a8ad52b19c363febbd.zip |
Make SIZEOF_SOCKADDR return socklen_t to avoid bad compares.
Diffstat (limited to 'src/common/compat.c')
-rw-r--r-- | src/common/compat.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/common/compat.c b/src/common/compat.c index 9e76592615..0b4e4a428d 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -1487,10 +1487,18 @@ tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2]) #ifdef NEED_ERSATZ_SOCKETPAIR -#define SIZEOF_SOCKADDR(domain) \ - (domain == AF_INET ? sizeof(struct sockaddr_in) : \ - (domain == AF_INET6 ? sizeof(struct sockaddr_in6) : \ - ((size_t)0) /* unsupported, don't match any valid size */)) +static INLINE socklen_t +SIZEOF_SOCKADDR(int domain) +{ + switch (domain) { + case AF_INET: + return sizeof(struct sockaddr_in); + case AF_INET6: + return sizeof(struct sockaddr_in6); + default: + return 0; + } +} /** * Helper used to implement socketpair on systems that lack it, by |