]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Various pointer and syntax errors.
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 10 Jan 2010 08:15:38 +0000 (21:15 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 10 Jan 2010 08:15:38 +0000 (21:15 +1300)
Uncovered by Pawel Worach using clang static analysis tool.

Fixes:
 * several NULL pointer dereferences
 * several unused variable return saves
 * a parentheses typo

lib/charset.c
lib/radix.c
src/cf_gen.cc
tools/cachemgr.cc

index c092f3fbdc001d27384af074093efe2b56b02fd1..b885941efe7f170e95032c2e482777f7dad80140 100644 (file)
 #include "config.h"
 #include "util.h"
 
-/* Convert ISO-LATIN-1 to UTF-8
- */
+/** Convert ISO-LATIN-1 to UTF-8 */
 char *
 latin1_to_utf8(char *out, size_t size, const char *in)
 {
-    unsigned char *p;
-    for (p = (unsigned char *)out; *in && size > 2; in++) {
+    unsigned char *p = (unsigned char *)out;
+    for (; *in && size > 2; in++) {
         unsigned char ch = (unsigned char)*in;
         if (ch < 0x80) {
             *p++ = ch;
@@ -46,10 +45,8 @@ latin1_to_utf8(char *out, size_t size, const char *in)
             size--;
         }
     }
-    *p++ = '\0';
+    *p = '\0';
     if (*in)
         return NULL;
     return out;
 }
-
-
index 94f81f832cfd1f2605f242d443a26adc424318ec..7210aad699eac98cf8046075128b5e861822bf77 100644 (file)
@@ -620,7 +620,8 @@ squid_rn_addroute(void *v_arg, void *n_arg, struct squid_radix_node_head *head,
         if (tt == saved_tt) {
             struct squid_radix_node *xx = x;
             /* link in at head of list */
-            (tt = treenodes)->rn_dupedkey = t;
+            tt = treenodes;
+            tt->rn_dupedkey = t;
             tt->rn_flags = t->rn_flags;
             tt->rn_p = x = t->rn_p;
             if (x->rn_l == t)
@@ -630,7 +631,8 @@ squid_rn_addroute(void *v_arg, void *n_arg, struct squid_radix_node_head *head,
             saved_tt = tt;
             x = xx;
         } else {
-            (tt = treenodes)->rn_dupedkey = t->rn_dupedkey;
+            tt = treenodes;
+            tt->rn_dupedkey = t->rn_dupedkey;
             t->rn_dupedkey = tt;
         }
 #ifdef RN_DEBUG
index d32a3e203f34e133b0545729a0e24b8f73ab0383..a3282f0ea99df52418f34b47b8576c23cb38f6f6 100644 (file)
@@ -865,6 +865,8 @@ gen_conf(Entry * head, FILE * fp, bool verbose_output)
 
         if (enabled || verbose_output) {
             for (line = entry->nocomment; line != NULL; line = line->next) {
+                if (!line->data)
+                    continue;
                 if (!enabled && line->data[0] != '#')
                     fprintf(fp, "#%s\n", line->data);
                 else
index 25800b8cf719c1e73c94968a623aa5ef962f7035..0a5df021e3076749de46b7f528f66f44b96bf1dc 100644 (file)
@@ -1,4 +1,4 @@
-/*
+1158/*
  * DEBUG: section 0     CGI Cache Manager
  * AUTHOR: Duane Wessels
  *
@@ -558,7 +558,7 @@ munge_other_line(const char *buf, cachemgr_request * req)
 
     xfree(buf_copy);
     /* record ends */
-    l += snprintf(html + l, sizeof(html) - l, "</tr>\n");
+    snprintf(html + l, sizeof(html) - l, "</tr>\n");
     next_is_header = is_header && strstr(buf, "\t\t");
     table_line_num++;
     return html;
@@ -819,7 +819,7 @@ process_request(cachemgr_request * req)
 
     if ( !S.IsAnyAddr() ) {
         (void) 0;
-    } else if ( S = req->hostname)
+    } else if ((S = req->hostname))
         (void) 0;
     else {
         snprintf(buf, 1024, "Unknown host: %s\n", req->hostname);
@@ -1155,8 +1155,7 @@ make_auth_header(const cachemgr_request * req)
 
     assert(stringLength < sizeof(buf));
 
-    stringLength += snprintf(&buf[stringLength], sizeof(buf) - stringLength,
-                             "Proxy-Authorization: Basic %s\r\n", str64);
+    snprintf(&buf[stringLength], sizeof(buf) - stringLength, "Proxy-Authorization: Basic %s\r\n", str64);
 
     return buf;
 }