From: Amos Jeffries Date: Sun, 10 Jan 2010 08:15:38 +0000 (+1300) Subject: Various pointer and syntax errors. X-Git-Tag: SQUID_3_2_0_1~476 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8df4471634fad62a3a748ba3ff39b0434736e758;p=thirdparty%2Fsquid.git Various pointer and syntax errors. Uncovered by Pawel Worach using clang static analysis tool. Fixes: * several NULL pointer dereferences * several unused variable return saves * a parentheses typo --- diff --git a/lib/charset.c b/lib/charset.c index c092f3fbdc..b885941efe 100644 --- a/lib/charset.c +++ b/lib/charset.c @@ -28,13 +28,12 @@ #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; } - - diff --git a/lib/radix.c b/lib/radix.c index 94f81f832c..7210aad699 100644 --- a/lib/radix.c +++ b/lib/radix.c @@ -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 diff --git a/src/cf_gen.cc b/src/cf_gen.cc index d32a3e203f..a3282f0ea9 100644 --- a/src/cf_gen.cc +++ b/src/cf_gen.cc @@ -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 diff --git a/tools/cachemgr.cc b/tools/cachemgr.cc index 25800b8cf7..0a5df021e3 100644 --- a/tools/cachemgr.cc +++ b/tools/cachemgr.cc @@ -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, "\n"); + snprintf(html + l, sizeof(html) - l, "\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; }