[tor-commits] [tor/master] scan-build: Add a check for result from getaddrinfo

nickm at torproject.org nickm at torproject.org
Fri Apr 25 05:30:23 UTC 2014


commit 08325b58bef83bfed181c493f269ef57477152c0
Author: Nick Mathewson <nickm at torproject.org>
Date:   Fri Apr 18 20:26:47 2014 -0400

    scan-build: Add a check for result from getaddrinfo
    
    As documented, getaddrinfo always sets its result when it returns
    no error.  But scan-build doesn't know that, and thinks we might
    be def
---
 src/common/address.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/common/address.c b/src/common/address.c
index e5930de..2825b12 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -236,7 +236,9 @@ tor_addr_lookup(const char *name, uint16_t family, tor_addr_t *addr)
     hints.ai_family = family;
     hints.ai_socktype = SOCK_STREAM;
     err = sandbox_getaddrinfo(name, NULL, &hints, &res);
-    if (!err) {
+    /* The check for 'res' here shouldn't be necessary, but it makes static
+     * analysis tools happy. */
+    if (!err && res) {
       best = NULL;
       for (res_p = res; res_p; res_p = res_p->ai_next) {
         if (family == AF_UNSPEC) {





More information about the tor-commits mailing list