]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Silence spurious clang warnings
authorteor <teor2345@gmail.com>
Sun, 26 Oct 2014 03:43:55 +0000 (14:43 +1100)
committerteor <teor2345@gmail.com>
Thu, 30 Oct 2014 11:34:46 +0000 (22:34 +1100)
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).

changes/spurious-clang-warnings [new file with mode: 0644]
src/common/compat.c
src/common/compat.h
src/common/crypto_pwbox.c
src/ext/ht.h
src/ext/tor_queue.h
src/or/channeltls.c
src/or/circuitmux_ewma.c
src/or/connection.h
src/or/or.h

diff --git a/changes/spurious-clang-warnings b/changes/spurious-clang-warnings
new file mode 100644 (file)
index 0000000..d039920
--- /dev/null
@@ -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.
index 0c048928d7b84f41245118f7d90c777102fdd6b0..e4758aaf8833204e99e90d3825f203555b32a525 100644 (file)
@@ -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) {
index a61ed009c16175ca3aa3080dabd476ce0aa0d7a5..f2eef5b6e7f9e86d5cb6c9ce9782d1b067a5f783 100644 (file)
@@ -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
index 91659db2bcbd6cf75a93adaa9360163221edd22b..b866c7ef391f3d7ea834395d5f74a476c5da113a 100644 (file)
@@ -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
index 1cca28ef4d759d620cc2826d231bfd0a0be4c3aa..09f5dcccd5c5740952934ad37cd4ce2abefb055f 100644 (file)
@@ -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)                           \
index f05e48c18e39cfe2de1ebe7d5c35da0e4c8a24c1..a6530c2b9bd84c5e96c33ea8a164d97ab5e0a0f4 100644 (file)
@@ -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);                            \
index f5f345b3e5aba47dd7d373a84165ac7f28fdba86..db044aee568ffb9097a377141b498fdb53b1e51c 100644 (file)
@@ -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);
 
index d8cd6c32611925ae32178c699d3d25c2c57f7900..49d899e5e7b35854ed6b131b833b4e450b6f94bb 100644 (file)
@@ -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;
index 917a6fbe370183ac734dcde6bf3cb478862189d0..7cdfd3e253c6a31ee5fba32680515056c6887350 100644 (file)
@@ -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);
index eaf609287db1cd5def34899d5521ed6cee22e382..6170c2119ccdf07000ae5fd592aaf4936c85d012 100644 (file)
@@ -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)