]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup: refactor to remove various dead code
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 25 Jul 2015 14:19:36 +0000 (07:19 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 25 Jul 2015 14:19:36 +0000 (07:19 -0700)
... detected by or confusing Coverity Scan.

These have been marked False Positive / Intentional earlier.
But long term the best fix is to simply clean out the dead code.

lib/rfc2617.c
src/ConfigParser.cc
src/cf_gen.cc
src/peer_digest.cc
src/peer_select.cc
src/wccp2.cc

index c66dd3b15da98eafbd1e1a43e1cc6376f075378c..6f6ae5875e471d4138953c2089aada192bd380c0 100644 (file)
@@ -67,14 +67,20 @@ CvtBin(const HASHHEX Hex, HASH Bin)
         else
             Bin[i / 2] |= n;
     }
-    /* FIXME: Coverity detects the below as dead code.
+
+#if HASHHEXLEN != (2*HASHLEN)
+    /*
       Why? :: right here i == 32
         which means the first step of the for loop makes i==16
         and cannot be < HASHLEN (which is also 16)
+
+      But only guaranteed if HASHHEXLEN == 2*HASHLEN
+      This will ensure correct 0-ing of bins no matter what.
     */
     for (i = i / 2; i < HASHLEN; i++) {
         Bin[i] = '\0';
     }
+#endif
 }
 
 /* calculate H(A1) as per spec */
index 1445787b06bbb93cf46645c72d12cee2488ab9c6..827d76f2594b97e8cdaffb4584a94e3da4b755c9 100644 (file)
@@ -67,9 +67,9 @@ ConfigParser::TokenPutBack(const char *tok)
 char *
 ConfigParser::Undo()
 {
-    LOCAL_ARRAY(char, undoToken, CONFIG_LINE_LIMIT);
+    static char undoToken[CONFIG_LINE_LIMIT];
     if (!Undo_.empty()) {
-        strncpy(undoToken, Undo_.front().c_str(), sizeof(undoToken));
+        xstrncpy(undoToken, Undo_.front().c_str(), sizeof(undoToken));
         undoToken[sizeof(undoToken) - 1] = '\0';
         if (!PreviewMode_)
             Undo_.pop();
@@ -88,7 +88,7 @@ ConfigParser::strtokFile()
     static FILE *wordFile = NULL;
 
     char *t;
-    LOCAL_ARRAY(char, buf, CONFIG_LINE_LIMIT);
+    static char buf[CONFIG_LINE_LIMIT];
 
     if ((t = ConfigParser::Undo()))
         return t;
@@ -126,7 +126,7 @@ ConfigParser::strtokFile()
         }
 
         /* fromFile */
-        if (fgets(buf, CONFIG_LINE_LIMIT, wordFile) == NULL) {
+        if (fgets(buf, sizeof(buf), wordFile) == NULL) {
             /* stop reading from file */
             fclose(wordFile);
             wordFile = NULL;
@@ -218,7 +218,7 @@ ConfigParser::UnQuote(const char *token, const char **next)
 
     if (errorStr) {
         if (PreviewMode_)
-            strncpy(UnQuoted, SQUID_ERROR_TOKEN, sizeof(UnQuoted));
+            xstrncpy(UnQuoted, SQUID_ERROR_TOKEN, sizeof(UnQuoted));
         else {
             debugs(3, DBG_CRITICAL, "FATAL: " << errorStr << ": " << errorPos);
             self_destruct();
index 30d4b5652e8b0ef9b0641a4704daf4b3859ac66e..880f73a976c6f9426505388f338e9a52cf4feded 100644 (file)
@@ -391,10 +391,11 @@ main(int argc, char *argv[])
                     entries.back().nocomment.push_back(buff);
                 }
                 break;
-
+#if 0
             case sEXIT:
                 assert(0);      /* should never get here */
                 break;
+#endif
             }
 
     }
index 648f6c3c4c1d5aaba059d0fa3a9d03adc53b4d97..189c618cdec84a730fd62794b31a8a00bf912515 100644 (file)
@@ -633,19 +633,15 @@ peerDigestSwapInHeaders(void *data, char *buf, ssize_t size)
 
         fetch->state = DIGEST_READ_CBLOCK;
         return hdr_size;    /* Say how much data we read */
-    } else {
-        /* need more data, do we have space? */
+    }
 
-        if (size >= SM_PAGE_SIZE) {
-            peerDigestFetchAbort(fetch, buf, "stored header too big");
-            return -1;
-        } else {
-            return 0;       /* We need to read more to parse .. */
-        }
+    /* need more data, do we have space? */
+    if (size >= SM_PAGE_SIZE) {
+        peerDigestFetchAbort(fetch, buf, "stored header too big");
+        return -1;
     }
 
-    fatal("peerDigestSwapInHeaders() - shouldn't get here!\n");
-    return 0; /* keep gcc happy */
+    return 0;       /* We need to read more to parse .. */
 }
 
 int
@@ -674,19 +670,15 @@ peerDigestSwapInCBlock(void *data, char *buf, ssize_t size)
             peerDigestFetchAbort(fetch, buf, "invalid digest cblock");
             return -1;
         }
-    } else {
-        /* need more data, do we have space? */
+    }
 
-        if (size >= SM_PAGE_SIZE) {
-            peerDigestFetchAbort(fetch, buf, "digest cblock too big");
-            return -1;
-        } else {
-            return 0;       /* We need more data */
-        }
+    /* need more data, do we have space? */
+    if (size >= SM_PAGE_SIZE) {
+        peerDigestFetchAbort(fetch, buf, "digest cblock too big");
+        return -1;
     }
 
-    fatal("peerDigestSwapInCBlock(): shouldn't get here!\n");
-    return 0; /* keep gcc happy */
+    return 0;       /* We need more data */
 }
 
 int
@@ -717,13 +709,10 @@ peerDigestSwapInMask(void *data, char *buf, ssize_t size)
         assert(fetch->mask_offset == pd->cd->mask_size);
         assert(peerDigestFetchedEnough(fetch, NULL, 0, "peerDigestSwapInMask"));
         return -1;      /* XXX! */
-    } else {
-        /* We always read everything, so return so */
-        return size;
     }
 
-    fatal("peerDigestSwapInMask(): shouldn't get here!\n");
-    return 0; /* keep gcc happy */
+    /* We always read everything, so return size */
+    return size;
 }
 
 static int
index 211aff957371ba5987138e5d28f3f6cebd4e37af..20b3688542221946919bbddb1b1f1d3705842236 100644 (file)
@@ -748,11 +748,12 @@ peerPingTimeout(void *data)
     StoreEntry *entry = psstate->entry;
 
     if (entry)
-        debugs(44, 3, "peerPingTimeout: '" << psstate->url() << "'" );
+        debugs(44, 3, psstate->url());
 
     if (!cbdataReferenceValid(psstate->callback_data)) {
         /* request aborted */
-        entry->ping_status = PING_DONE;
+        if (entry)
+            entry->ping_status = PING_DONE;
         cbdataReferenceDone(psstate->callback_data);
         delete psstate;
         return;
index 9f2b086410e5ba2b8b229cd0697682d81d1ad439..36317344d9627d7e02e945b44718ab6c7efa08d6 100644 (file)
@@ -2335,8 +2335,6 @@ parse_wccp2_service_info(void *)
 void
 dump_wccp2_service_info(StoreEntry * e, const char *label, void *)
 {
-    char comma;
-
     struct wccp2_service_list_t *srv;
     int flags;
     srv = wccp2_service_list_head;
@@ -2362,102 +2360,102 @@ dump_wccp2_service_info(StoreEntry * e, const char *label, void *)
         /* flags */
         flags = ntohl(srv->info.service_flags);
 
+        bool comma = false;
         if (flags != 0) {
-            comma = 0;
             storeAppendPrintf(e, " flags=");
 
             if (flags & WCCP2_SERVICE_SRC_IP_HASH) {
-                storeAppendPrintf(e, "%ssrc_ip_hash", comma ? "," : "");
-                comma = 1;
+                storeAppendPrintf(e, "src_ip_hash");
+                comma = true;
             }
 
             if (flags & WCCP2_SERVICE_DST_IP_HASH) {
                 storeAppendPrintf(e, "%sdst_ip_hash", comma ? "," : "");
-                comma = 1;
+                comma = true;
             }
 
             if (flags & WCCP2_SERVICE_SRC_PORT_HASH) {
                 storeAppendPrintf(e, "%ssource_port_hash", comma ? "," : "");
-                comma = 1;
+                comma = true;
             }
 
             if (flags & WCCP2_SERVICE_DST_PORT_HASH) {
                 storeAppendPrintf(e, "%sdst_port_hash", comma ? "," : "");
-                comma = 1;
+                comma = true;
             }
 
             if (flags & WCCP2_SERVICE_PORTS_DEFINED) {
                 storeAppendPrintf(e, "%sports_defined", comma ? "," : "");
-                comma = 1;
+                comma = true;
             }
 
             if (flags & WCCP2_SERVICE_PORTS_SOURCE) {
                 storeAppendPrintf(e, "%sports_source", comma ? "," : "");
-                comma = 1;
+                comma = true;
             }
 
             if (flags & WCCP2_SERVICE_SRC_IP_ALT_HASH) {
                 storeAppendPrintf(e, "%ssrc_ip_alt_hash", comma ? "," : "");
-                comma = 1;
+                comma = true;
             }
 
             if (flags & WCCP2_SERVICE_DST_IP_ALT_HASH) {
                 storeAppendPrintf(e, "%ssrc_ip_alt_hash", comma ? "," : "");
-                comma = 1;
+                comma = true;
             }
 
             if (flags & WCCP2_SERVICE_SRC_PORT_ALT_HASH) {
                 storeAppendPrintf(e, "%ssrc_port_alt_hash", comma ? "," : "");
-                comma = 1;
+                comma = true;
             }
 
             if (flags & WCCP2_SERVICE_DST_PORT_ALT_HASH) {
                 storeAppendPrintf(e, "%sdst_port_alt_hash", comma ? "," : "");
-                comma = 1;
+                //comma = true; // uncomment if more options added
             }
         }
 
         /* ports */
-        comma = 0;
+        comma = false;
 
         if (srv->info.port0 != 0) {
-            storeAppendPrintf(e, "%s%d", comma ? "," : " ports=", ntohs(srv->info.port0));
-            comma = 1;
+            storeAppendPrintf(e, " ports=%d", ntohs(srv->info.port0));
+            comma = true;
         }
 
         if (srv->info.port1 != 0) {
             storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port1));
-            comma = 1;
+            comma = true;
         }
 
         if (srv->info.port2 != 0) {
             storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port2));
-            comma = 1;
+            comma = true;
         }
 
         if (srv->info.port3 != 0) {
             storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port3));
-            comma = 1;
+            comma = true;
         }
 
         if (srv->info.port4 != 0) {
             storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port4));
-            comma = 1;
+            comma = true;
         }
 
         if (srv->info.port5 != 0) {
             storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port5));
-            comma = 1;
+            comma = true;
         }
 
         if (srv->info.port6 != 0) {
             storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port6));
-            comma = 1;
+            comma = true;
         }
 
         if (srv->info.port7 != 0) {
             storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port7));
-            comma = 1;
+            // comma = true; // uncomment if more options are added
         }
 
         /* protocol */