Fixes these warnings:

        gnutls.c:457:3: warning: Value stored to 'err' is never read
          err = 0;

        http-ntlm.c:477:5: warning: Value stored to 'size' is never read
          size = (size_t) snprintf (ntlmbuf, sizeof(ntlmbuf),

        http.c:1479:3: warning: Attempt to free released memory
          xfree_null (hs->error);

The last one *might* result in a crash under special circumstances.


I think we should just have one xfree() macro instead of two (xfree and
xfree_null, some parts of the code even use free() directly).

IMHO, a free'd pointer should always be set to NULL afterwards (as a good
programming convention). I suggest the following macro

#define xfree(a) do { if (a) { free ((void *) (a)); a = NULL; } } while (0)

What do you think ?

Tim
From 50ec4d9c3d0f3504baf40cb9d55fe0201edc8552 Mon Sep 17 00:00:00 2001
From: Tim Ruehsen <[email protected]>
Date: Tue, 18 Nov 2014 20:44:56 +0100
Subject: [PATCH] Fix warnings from clang-analyzer 3.6

---
 src/ChangeLog   |  11 +++++
 src/gnutls.c    |   1 -
 src/http-ntlm.c | 134 ++++++++++++++++++++++++++++----------------------------
 src/http.c      |   1 +
 4 files changed, 79 insertions(+), 68 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 87b1feb..4e974b0 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,14 @@
+2014-11-18  Tim Ruehsen  <[email protected]>
+
+	* Fix warnings from clang-analyzer 3.6
+
+	gnutls.c:457:3: warning: Value stored to 'err' is never read
+	  err = 0;
+	http-ntlm.c:477:5: warning: Value stored to 'size' is never read
+	  size = (size_t) snprintf (ntlmbuf, sizeof(ntlmbuf),
+	http.c:1479:3: warning: Attempt to free released memory
+	  xfree_null (hs->error);
+
 2014-11-17  Tim Ruehsen  <[email protected]>

 	* http.c: use c_strncasecmp() in BEGINS_WITH macro
diff --git a/src/gnutls.c b/src/gnutls.c
index 1744245..87d1d0b 100644
--- a/src/gnutls.c
+++ b/src/gnutls.c
@@ -454,7 +454,6 @@ ssl_connect_wget (int fd, const char *hostname)
   gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) FD_TO_SOCKET (fd));
 #endif

-  err = 0;
 #if HAVE_GNUTLS_PRIORITY_SET_DIRECT
   switch (opt.secure_protocol)
     {
diff --git a/src/http-ntlm.c b/src/http-ntlm.c
index d9b6884..d157a71 100644
--- a/src/http-ntlm.c
+++ b/src/http-ntlm.c
@@ -474,82 +474,82 @@ ntlm_output (struct ntlmdata *ntlm, const char *user, const char *passwd,

     /* Create the big type-3 message binary blob */

-    size = (size_t) snprintf (ntlmbuf, sizeof(ntlmbuf),
-                     "NTLMSSP%c"
-                     "\x03%c%c%c" /* type-3, 32 bits */
-
-                     "%c%c%c%c" /* LanManager length + allocated space */
-                     "%c%c" /* LanManager offset */
-                     "%c%c" /* 2 zeroes */
-
-                     "%c%c" /* NT-response length */
-                     "%c%c" /* NT-response allocated space */
-                     "%c%c" /* NT-response offset */
-                     "%c%c" /* 2 zeroes */
-
-                     "%c%c"  /* domain length */
-                     "%c%c"  /* domain allocated space */
-                     "%c%c"  /* domain name offset */
-                     "%c%c"  /* 2 zeroes */
-
-                     "%c%c"  /* user length */
-                     "%c%c"  /* user allocated space */
-                     "%c%c"  /* user offset */
-                     "%c%c"  /* 2 zeroes */
-
-                     "%c%c"  /* host length */
-                     "%c%c"  /* host allocated space */
-                     "%c%c"  /* host offset */
-                     "%c%c%c%c%c%c"  /* 6 zeroes */
-
-                     "\xff\xff"  /* message length */
-                     "%c%c"  /* 2 zeroes */
-
-                     "\x01\x82" /* flags */
-                     "%c%c"  /* 2 zeroes */
-
-                     /* domain string */
-                     /* user string */
-                     /* host string */
-                     /* LanManager response */
-                     /* NT response */
-                     ,
-                     0, /* zero termination */
-                     0,0,0, /* type-3 long, the 24 upper bits */
-
-                     SHORTPAIR(0x18),  /* LanManager response length, twice */
-                     SHORTPAIR(0x18),
-                     SHORTPAIR(lmrespoff),
-                     0x0, 0x0,
+    snprintf (ntlmbuf, sizeof (ntlmbuf),
+              "NTLMSSP%c"
+              "\x03%c%c%c" /* type-3, 32 bits */
+
+              "%c%c%c%c" /* LanManager length + allocated space */
+              "%c%c" /* LanManager offset */
+              "%c%c" /* 2 zeroes */
+
+              "%c%c" /* NT-response length */
+              "%c%c" /* NT-response allocated space */
+              "%c%c" /* NT-response offset */
+              "%c%c" /* 2 zeroes */
+
+              "%c%c" /* domain length */
+              "%c%c" /* domain allocated space */
+              "%c%c" /* domain name offset */
+              "%c%c" /* 2 zeroes */
+
+              "%c%c" /* user length */
+              "%c%c" /* user allocated space */
+              "%c%c" /* user offset */
+              "%c%c" /* 2 zeroes */
+
+              "%c%c" /* host length */
+              "%c%c" /* host allocated space */
+              "%c%c" /* host offset */
+              "%c%c%c%c%c%c" /* 6 zeroes */
+
+              "\xff\xff" /* message length */
+              "%c%c" /* 2 zeroes */
+
+              "\x01\x82" /* flags */
+              "%c%c" /* 2 zeroes */
+
+              /* domain string */
+              /* user string */
+              /* host string */
+              /* LanManager response */
+              /* NT response */
+              ,
+              0, /* zero termination */
+              0, 0, 0, /* type-3 long, the 24 upper bits */
+
+              SHORTPAIR (0x18), /* LanManager response length, twice */
+              SHORTPAIR (0x18),
+              SHORTPAIR (lmrespoff),
+              0x0, 0x0,

 #ifdef USE_NTRESPONSES
-                     SHORTPAIR(0x18),  /* NT-response length, twice */
-                     SHORTPAIR(0x18),
+                SHORTPAIR (0x18), /* NT-response length, twice */
+              SHORTPAIR (0x18),
 #else
-                     0x0, 0x0,
-                     0x0, 0x0,
+                0x0, 0x0,
+              0x0, 0x0,
 #endif
-                     SHORTPAIR(ntrespoff),
-                     0x0, 0x0,
+                SHORTPAIR (ntrespoff),
+              0x0, 0x0,

-                     SHORTPAIR(domlen),
-                     SHORTPAIR(domlen),
-                     SHORTPAIR(domoff),
-                     0x0, 0x0,
+              SHORTPAIR (domlen),
+              SHORTPAIR (domlen),
+              SHORTPAIR (domoff),
+              0x0, 0x0,

-                     SHORTPAIR(userlen),
-                     SHORTPAIR(userlen),
-                     SHORTPAIR(useroff),
-                     0x0, 0x0,
+              SHORTPAIR (userlen),
+              SHORTPAIR (userlen),
+              SHORTPAIR (useroff),
+              0x0, 0x0,

-                     SHORTPAIR(hostlen),
-                     SHORTPAIR(hostlen),
-                     SHORTPAIR(hostoff),
-                     0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+              SHORTPAIR (hostlen),
+              SHORTPAIR (hostlen),
+              SHORTPAIR (hostoff),
+              0x0, 0x0, 0x0, 0x0, 0x0, 0x0,

-                     0x0, 0x0,
+              0x0, 0x0,

-                     0x0, 0x0);
+              0x0, 0x0);

     /* size is now 64 */
     sized;
diff --git a/src/http.c b/src/http.c
index da40e98..dd9d7e4 100644
--- a/src/http.c
+++ b/src/http.c
@@ -3428,6 +3428,7 @@ Remote file exists.\n\n"));
               xfree_null (hstat.message);
               xfree_null (hstat.error);
               hstat.message = NULL;
+              hstat.error = NULL;
               continue;
             } /* send_head_first */
         } /* !got_head */
--
2.1.3

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to