From: Amos Jeffries Date: Sat, 25 Jul 2015 14:19:36 +0000 (-0700) Subject: Cleanup: refactor to remove various dead code X-Git-Tag: merge-candidate-3-v1~32^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cfd861ab1795a49dd64b715af3f92642fec68c32;p=thirdparty%2Fsquid.git Cleanup: refactor to remove various dead code ... 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. --- diff --git a/lib/rfc2617.c b/lib/rfc2617.c index c66dd3b15d..6f6ae5875e 100644 --- a/lib/rfc2617.c +++ b/lib/rfc2617.c @@ -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 */ diff --git a/src/ConfigParser.cc b/src/ConfigParser.cc index 1445787b06..827d76f259 100644 --- a/src/ConfigParser.cc +++ b/src/ConfigParser.cc @@ -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(); diff --git a/src/cf_gen.cc b/src/cf_gen.cc index 30d4b5652e..880f73a976 100644 --- a/src/cf_gen.cc +++ b/src/cf_gen.cc @@ -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 } } diff --git a/src/peer_digest.cc b/src/peer_digest.cc index 648f6c3c4c..189c618cde 100644 --- a/src/peer_digest.cc +++ b/src/peer_digest.cc @@ -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 diff --git a/src/peer_select.cc b/src/peer_select.cc index 211aff9573..20b3688542 100644 --- a/src/peer_select.cc +++ b/src/peer_select.cc @@ -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; diff --git a/src/wccp2.cc b/src/wccp2.cc index 9f2b086410..36317344d9 100644 --- a/src/wccp2.cc +++ b/src/wccp2.cc @@ -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 */