diff --git a/changes/spurious-clang-warnings b/changes/spurious-clang-warnings new file mode 100644 index 0000000000..d039920476 --- /dev/null +++ b/changes/spurious-clang-warnings @@ -0,0 +1,10 @@ + o Minor bugfixes: + - Silence clang warnings under --enable-expensive-hardening, including: + + implicit truncation of 64 bit values to 32 bit; + + const char assignment to self; + + tautological compare; and + + additional parentheses around equality tests. (gcc uses these to + silence assignment, so clang warns when they're present in an + equality test. But we need to use extra parentheses in macros to + isolate them from other code). + Fixes bug 13577. diff --git a/src/common/compat.c b/src/common/compat.c index 0c048928d7..e4758aaf88 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -138,9 +138,10 @@ int tor_open_cloexec(const char *path, int flags, unsigned mode) { int fd; + const char *p = path; #ifdef O_CLOEXEC - path = sandbox_intern_string(path); - fd = open(path, flags|O_CLOEXEC, mode); + p = sandbox_intern_string(path); + fd = open(p, flags|O_CLOEXEC, mode); if (fd >= 0) return fd; /* If we got an error, see if it is EINVAL. EINVAL might indicate that, @@ -150,8 +151,8 @@ tor_open_cloexec(const char *path, int flags, unsigned mode) return -1; #endif - log_debug(LD_FS, "Opening %s with flags %x", path, flags); - fd = open(path, flags, mode); + log_debug(LD_FS, "Opening %s with flags %x", p, flags); + fd = open(p, flags, mode); #ifdef FD_CLOEXEC if (fd >= 0) { if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { diff --git a/src/common/compat.h b/src/common/compat.h index a61ed009c1..f2eef5b6e7 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -562,17 +562,18 @@ const char *tor_socket_strerror(int e); #else #define SOCK_ERRNO(e) e #if EAGAIN == EWOULDBLOCK -#define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN) +/* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */ +#define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN || 0) #else #define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN || (e) == EWOULDBLOCK) #endif -#define ERRNO_IS_EINPROGRESS(e) ((e) == EINPROGRESS) -#define ERRNO_IS_CONN_EINPROGRESS(e) ((e) == EINPROGRESS) +#define ERRNO_IS_EINPROGRESS(e) ((e) == EINPROGRESS || 0) +#define ERRNO_IS_CONN_EINPROGRESS(e) ((e) == EINPROGRESS || 0) #define ERRNO_IS_ACCEPT_EAGAIN(e) \ (ERRNO_IS_EAGAIN(e) || (e) == ECONNABORTED) #define ERRNO_IS_ACCEPT_RESOURCE_LIMIT(e) \ ((e) == EMFILE || (e) == ENFILE || (e) == ENOBUFS || (e) == ENOMEM) -#define ERRNO_IS_EADDRINUSE(e) ((e) == EADDRINUSE) +#define ERRNO_IS_EADDRINUSE(e) (((e) == EADDRINUSE) || 0) #define tor_socket_errno(sock) (errno) #define tor_socket_strerror(e) strerror(e) #endif diff --git a/src/common/crypto_pwbox.c b/src/common/crypto_pwbox.c index 91659db2bc..b866c7ef39 100644 --- a/src/common/crypto_pwbox.c +++ b/src/common/crypto_pwbox.c @@ -62,7 +62,7 @@ crypto_pwbox(uint8_t **out, size_t *outlen_out, pwbox_encoded_setlen_data(enc, encrypted_len); encrypted_portion = pwbox_encoded_getarray_data(enc); - set_uint32(encrypted_portion, htonl(input_len)); + set_uint32(encrypted_portion, htonl((uint32_t)input_len)); memcpy(encrypted_portion+4, input, input_len); /* Now that all the data is in position, derive some keys, encrypt, and diff --git a/src/ext/ht.h b/src/ext/ht.h index 1cca28ef4d..09f5dcccd5 100644 --- a/src/ext/ht.h +++ b/src/ext/ht.h @@ -38,8 +38,9 @@ } #endif +/* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */ #define HT_EMPTY(head) \ - ((head)->hth_n_entries == 0) + (((head)->hth_n_entries == 0) || 0) /* How many elements in 'head'? */ #define HT_SIZE(head) \ diff --git a/src/ext/tor_queue.h b/src/ext/tor_queue.h index f05e48c18e..a6530c2b9b 100644 --- a/src/ext/tor_queue.h +++ b/src/ext/tor_queue.h @@ -109,7 +109,8 @@ struct { \ */ #define TOR_SLIST_FIRST(head) ((head)->slh_first) #define TOR_SLIST_END(head) NULL -#define TOR_SLIST_EMPTY(head) (SLIST_FIRST(head) == TOR_SLIST_END(head)) +/* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */ +#define TOR_SLIST_EMPTY(head) ((SLIST_FIRST(head) == TOR_SLIST_END(head)) || 0) #define TOR_SLIST_NEXT(elm, field) ((elm)->field.sle_next) #define TOR_SLIST_FOREACH(var, head, field) \ @@ -181,9 +182,11 @@ struct { \ /* * List access methods */ -#define TOR_LIST_FIRST(head) ((head)->lh_first) -#define TOR_LIST_END(head) NULL -#define TOR_LIST_EMPTY(head) (TOR_LIST_FIRST(head) == TOR_LIST_END(head)) +#define TOR_LIST_FIRST(head) ((head)->lh_first) +#define TOR_LIST_END(head) NULL +/* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */ +#define TOR_LIST_EMPTY(head) \ + ((TOR_LIST_FIRST(head) == TOR_LIST_END(head)) || 0) #define TOR_LIST_NEXT(elm, field) ((elm)->field.le_next) #define TOR_LIST_FOREACH(var, head, field) \ @@ -265,8 +268,10 @@ struct { \ * Simple queue access methods. */ #define TOR_SIMPLEQ_FIRST(head) ((head)->sqh_first) -#define TOR_SIMPLEQ_END(head) NULL -#define TOR_SIMPLEQ_EMPTY(head) (TOR_SIMPLEQ_FIRST(head) == TOR_SIMPLEQ_END(head)) +#define TOR_SIMPLEQ_END(head) NULL +/* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */ +#define TOR_SIMPLEQ_EMPTY(head) \ + ((TOR_SIMPLEQ_FIRST(head) == TOR_SIMPLEQ_END(head)) || 0) #define TOR_SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next) #define TOR_SIMPLEQ_FOREACH(var, head, field) \ @@ -345,8 +350,9 @@ struct { \ /* XXX */ #define TOR_TAILQ_PREV(elm, headname, field) \ (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) +/* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */ #define TOR_TAILQ_EMPTY(head) \ - (TOR_TAILQ_FIRST(head) == TOR_TAILQ_END(head)) + ((TOR_TAILQ_FIRST(head) == TOR_TAILQ_END(head)) || 0) #define TOR_TAILQ_FOREACH(var, head, field) \ for((var) = TOR_TAILQ_FIRST(head); \ @@ -462,8 +468,9 @@ struct { \ #define TOR_CIRCLEQ_END(head) ((void *)(head)) #define TOR_CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next) #define TOR_CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev) +/* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */ #define TOR_CIRCLEQ_EMPTY(head) \ - (TOR_CIRCLEQ_FIRST(head) == TOR_CIRCLEQ_END(head)) + ((TOR_CIRCLEQ_FIRST(head) == TOR_CIRCLEQ_END(head)) || 0) #define TOR_CIRCLEQ_FOREACH(var, head, field) \ for((var) = TOR_CIRCLEQ_FIRST(head); \ diff --git a/src/or/channeltls.c b/src/or/channeltls.c index f5f345b3e5..db044aee56 100644 --- a/src/or/channeltls.c +++ b/src/or/channeltls.c @@ -847,8 +847,8 @@ channel_tls_handle_state_change_on_orconn(channel_tls_t *chan, tor_assert(conn); tor_assert(conn->chan == chan); tor_assert(chan->conn == conn); - /* -Werror appeasement */ - tor_assert(old_state == old_state); + /* Shut the compiler up without triggering -Wtautological-compare */ + (void)old_state; base_chan = TLS_CHAN_TO_BASE(chan); diff --git a/src/or/circuitmux_ewma.c b/src/or/circuitmux_ewma.c index d8cd6c3261..49d899e5e7 100644 --- a/src/or/circuitmux_ewma.c +++ b/src/or/circuitmux_ewma.c @@ -273,8 +273,8 @@ ewma_alloc_circ_data(circuitmux_t *cmux, tor_assert(circ); tor_assert(direction == CELL_DIRECTION_OUT || direction == CELL_DIRECTION_IN); - /* Shut the compiler up */ - tor_assert(cell_count == cell_count); + /* Shut the compiler up without triggering -Wtautological-compare */ + (void)cell_count; cdata = tor_malloc_zero(sizeof(*cdata)); cdata->base_.magic = EWMA_POL_CIRC_DATA_MAGIC; diff --git a/src/or/connection.h b/src/or/connection.h index 917a6fbe37..7cdfd3e253 100644 --- a/src/or/connection.h +++ b/src/or/connection.h @@ -189,7 +189,8 @@ dir_connection_t *connection_dir_get_by_purpose_and_resource( int any_other_active_or_conns(const or_connection_t *this_conn); -#define connection_speaks_cells(conn) ((conn)->type == CONN_TYPE_OR) +/* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */ +#define connection_speaks_cells(conn) (((conn)->type == CONN_TYPE_OR) || 0) int connection_is_listener(connection_t *conn); int connection_state_is_open(connection_t *conn); int connection_state_is_connecting(connection_t *conn); diff --git a/src/or/or.h b/src/or/or.h index eaf609287d..6170c2119c 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -241,7 +241,7 @@ typedef enum { #define PROXY_CONNECT 1 #define PROXY_SOCKS4 2 #define PROXY_SOCKS5 3 -/* !!!! If there is ever a PROXY_* type over 2, we must grow the proxy_type +/* !!!! If there is ever a PROXY_* type over 3, we must grow the proxy_type * field in or_connection_t */ /* Pluggable transport proxy type. Don't use this in or_connection_t, @@ -4317,7 +4317,8 @@ static INLINE void or_state_mark_dirty(or_state_t *state, time_t when) /** Please turn this IP address into an FQDN, privately. */ #define SOCKS_COMMAND_RESOLVE_PTR 0xF1 -#define SOCKS_COMMAND_IS_CONNECT(c) ((c)==SOCKS_COMMAND_CONNECT) +/* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */ +#define SOCKS_COMMAND_IS_CONNECT(c) (((c)==SOCKS_COMMAND_CONNECT) || 0) #define SOCKS_COMMAND_IS_RESOLVE(c) ((c)==SOCKS_COMMAND_RESOLVE || \ (c)==SOCKS_COMMAND_RESOLVE_PTR)