[tor-commits] [tor/master] Fix clang warning, IPv6 address comment, buffer size typo

nickm at torproject.org nickm at torproject.org
Mon Jan 12 19:20:54 UTC 2015


commit 6a9cae2e1dafb756b30fda541e8b5d68cfd45f89
Author: teor <teor2345 at gmail.com>
Date:   Sat Dec 20 22:20:54 2014 +1100

    Fix clang warning, IPv6 address comment, buffer size typo
    
    The address of an array in the middle of a structure will
    always be non-NULL. clang recognises this and complains.
    Disable the tautologous and redundant check to silence
    this warning.
    
    A comment about an IPv6 address string incorrectly refers
    to an IPv4 address format.
    
    A log buffer is sized 10024 rather than 10240.
    
    Fixes bug 14001.
---
 changes/bug14001-clang-warning |    6 ++++++
 src/common/address.c           |    3 ++-
 src/common/log.c               |    2 +-
 src/or/connection_edge.c       |   11 ++++++++++-
 4 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/changes/bug14001-clang-warning b/changes/bug14001-clang-warning
new file mode 100644
index 0000000..b932af6
--- /dev/null
+++ b/changes/bug14001-clang-warning
@@ -0,0 +1,6 @@
+  o Minor bugfixes:
+    - The address of an array in the middle of a structure will
+      always be non-NULL. clang recognises this and complains.
+      Disable the tautologous and redundant check to silence
+      this warning.
+      Fixes bug 14001.
diff --git a/src/common/address.c b/src/common/address.c
index a3b5df6..0b475fc 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -1119,7 +1119,8 @@ fmt_addr32(uint32_t addr)
 int
 tor_addr_parse(tor_addr_t *addr, const char *src)
 {
-  char *tmp = NULL; /* Holds substring if we got a dotted quad. */
+  /* Holds substring of IPv6 address after removing square brackets */
+  char *tmp = NULL;
   int result;
   struct in_addr in_tmp;
   struct in6_addr in6_tmp;
diff --git a/src/common/log.c b/src/common/log.c
index ad0da7d..0a21ffb 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -451,7 +451,7 @@ MOCK_IMPL(STATIC void,
 logv,(int severity, log_domain_mask_t domain, const char *funcname,
      const char *suffix, const char *format, va_list ap))
 {
-  char buf[10024];
+  char buf[10240];
   size_t msg_len = 0;
   int formatted = 0;
   logfile_t *lf;
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 9ace375..9859cc2 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -744,8 +744,17 @@ connection_ap_fail_onehop(const char *failed_digest,
       /* we don't know the digest; have to compare addr:port */
       tor_addr_t addr;
       if (!build_state || !build_state->chosen_exit ||
-          !entry_conn->socks_request || !entry_conn->socks_request->address)
+          !entry_conn->socks_request) {
+        /* clang thinks that an array midway through a structure
+         * will never have a NULL address, under either:
+         * -Wpointer-bool-conversion if using !, or
+         * -Wtautological-pointer-compare if using == or !=
+         * It's probably right (unless pointers overflow and wrap),
+         * so we just skip this check
+         || !entry_conn->socks_request->address
+         */
         continue;
+      }
       if (tor_addr_parse(&addr, entry_conn->socks_request->address)<0 ||
           !tor_addr_eq(&build_state->chosen_exit->addr, &addr) ||
           build_state->chosen_exit->port != entry_conn->socks_request->port)





More information about the tor-commits mailing list