From 00d049f852ed009331cbf8603754c06b4fcb41ca Mon Sep 17 00:00:00 2001 From: ezelko260 Date: Tue, 28 Jan 2020 19:04:23 +0000 Subject: [PATCH 1/3] Removing always true/false comparisons. To me these are the ones that made the most sense to remove. There are some others reported that are: 1) Seem to be false positives due to enum usages for some reason 2) Seemed to me that they should be left in for readability purposes. These ones were constant comparisons but when viewed in the code they were in it made sense to leave them because it fit the code scheme and helped readability --- iocore/eventsystem/IOBuffer.cc | 2 +- iocore/net/SSLUtils.cc | 2 +- plugins/experimental/memcache/tsmemcache.cc | 2 +- plugins/experimental/uri_signing/uri_signing.c | 9 +++------ proxy/hdrs/HdrTest.cc | 8 ++++---- proxy/http/HttpSM.cc | 4 ++-- proxy/http/remap/RemapConfig.cc | 4 ---- 7 files changed, 12 insertions(+), 19 deletions(-) diff --git a/iocore/eventsystem/IOBuffer.cc b/iocore/eventsystem/IOBuffer.cc index ac04946b32f..61f71f56086 100644 --- a/iocore/eventsystem/IOBuffer.cc +++ b/iocore/eventsystem/IOBuffer.cc @@ -116,7 +116,7 @@ MIOBuffer::write(IOBufferBlock const *b, int64_t alen, int64_t offset) continue; } int64_t bytes; - if (len < 0 || len >= max_bytes) { + if (len >= max_bytes) { bytes = max_bytes; } else { bytes = len; diff --git a/iocore/net/SSLUtils.cc b/iocore/net/SSLUtils.cc index 812fd49c656..779f0301d2a 100644 --- a/iocore/net/SSLUtils.cc +++ b/iocore/net/SSLUtils.cc @@ -409,7 +409,7 @@ ssl_client_hello_callback(SSL *s, int *al, void *arg) * The list in practice only has a single element, so we only consider * the first one. */ - if (remaining != 0 && *p++ == TLSEXT_NAMETYPE_host_name) { + if (*p++ == TLSEXT_NAMETYPE_host_name) { remaining--; /* Now we can finally pull out the byte array with the actual hostname. */ if (remaining > 2) { diff --git a/plugins/experimental/memcache/tsmemcache.cc b/plugins/experimental/memcache/tsmemcache.cc index f8e5789227a..bdb2ebe5512 100644 --- a/plugins/experimental/memcache/tsmemcache.cc +++ b/plugins/experimental/memcache/tsmemcache.cc @@ -1628,7 +1628,7 @@ TSPluginInit(int argc, const char *argv[]) if (argc < 2) { TSError("[tsmemcache] Usage: tsmemcache.so [accept_port]\n"); goto error; - } else if (argc > 1) { + } else { int port = atoi(argv[1]); if (!port) { TSError("[tsmemcache] bad accept_port '%s'\n", argv[1]); diff --git a/plugins/experimental/uri_signing/uri_signing.c b/plugins/experimental/uri_signing/uri_signing.c index 30c8e4532e3..fe6793bee84 100644 --- a/plugins/experimental/uri_signing/uri_signing.c +++ b/plugins/experimental/uri_signing/uri_signing.c @@ -188,9 +188,7 @@ TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) TSHandleMLocRelease(mbuf, TS_NULL_MLOC, ul); PluginDebug("Processing request for %.*s.", url_ct, url); - if (cpi < max_cpi) { - checkpoints[cpi++] = mark_timer(&t); - } + checkpoints[cpi++] = mark_timer(&t); int strip_size = url_ct + 1; strip_uri = (char *)TSmalloc(strip_size); @@ -199,9 +197,8 @@ TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) size_t strip_ct; cjose_jws_t *jws = get_jws_from_uri(url, url_ct, package, strip_uri, strip_size, &strip_ct); - if (cpi < max_cpi) { - checkpoints[cpi++] = mark_timer(&t); - } + checkpoints[cpi++] = mark_timer(&t); + int checked_cookies = 0; if (!jws) { check_cookies: diff --git a/proxy/hdrs/HdrTest.cc b/proxy/hdrs/HdrTest.cc index b0f84d39f11..146e80dc614 100644 --- a/proxy/hdrs/HdrTest.cc +++ b/proxy/hdrs/HdrTest.cc @@ -565,7 +565,7 @@ HdrTest::test_http_aux(const char *request, const char *response) if (err == PARSE_RESULT_ERROR) { req_hdr.destroy(); rsp_hdr.destroy(); - return (failures_to_status("test_http_aux", (status == 0))); + return (failures_to_status("test_http_aux", false)); } /*** useless copy to exercise copy function ***/ @@ -606,7 +606,7 @@ HdrTest::test_http_aux(const char *request, const char *response) if (err == PARSE_RESULT_ERROR) { req_hdr.destroy(); rsp_hdr.destroy(); - return (failures_to_status("test_http_aux", (status == 0))); + return (failures_to_status("test_http_aux", false)); } http_parser_clear(&parser); @@ -655,7 +655,7 @@ HdrTest::test_http_aux(const char *request, const char *response) req_hdr.destroy(); rsp_hdr.destroy(); - return (failures_to_status("test_http_aux", (status == 0))); + return (failures_to_status("test_http_aux", false)); } int @@ -1599,7 +1599,7 @@ HdrTest::test_http_mutation() resp_hdr.destroy(); - return (failures_to_status("test_http_mutation", (status == 0))); + return (failures_to_status("test_http_mutation", false)); } /*------------------------------------------------------------------------- diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc index c03bd23cff4..a1df461eab5 100644 --- a/proxy/http/HttpSM.cc +++ b/proxy/http/HttpSM.cc @@ -4305,7 +4305,7 @@ HttpSM::parse_range_and_compare(MIMEField *field, int64_t content_length) ; } - if (s < e || start < 0) { + if (s < e) { t_state.range_setup = HttpTransact::RANGE_NONE; goto Lfaild; } @@ -4345,7 +4345,7 @@ HttpSM::parse_range_and_compare(MIMEField *field, int64_t content_length) ; } - if (s < e || end < 0) { + if (s < e) { t_state.range_setup = HttpTransact::RANGE_NONE; goto Lfaild; } diff --git a/proxy/http/remap/RemapConfig.cc b/proxy/http/remap/RemapConfig.cc index 985aee7779c..b3b1a467aba 100644 --- a/proxy/http/remap/RemapConfig.cc +++ b/proxy/http/remap/RemapConfig.cc @@ -875,10 +875,6 @@ process_regex_mapping_config(const char *from_host_lower, url_mapping *new_mappi to_host = new_mapping->toURL.host_get(&to_host_len); for (int i = 0; i < (to_host_len - 1); ++i) { if (to_host[i] == '$') { - if (substitution_count > UrlRewrite::MAX_REGEX_SUBS) { - Warning("Cannot have more than %d substitutions in mapping with host [%s]", UrlRewrite::MAX_REGEX_SUBS, from_host_lower); - goto lFail; - } substitution_id = to_host[i + 1] - '0'; if ((substitution_id < 0) || (substitution_id > captures)) { Warning("Substitution id [%c] has no corresponding capture pattern in regex [%s]", to_host[i + 1], from_host_lower); From 8e34fedef7bfc540697359d8c4fc1e22d1ae3036 Mon Sep 17 00:00:00 2001 From: ezelko260 Date: Tue, 28 Jan 2020 19:31:22 +0000 Subject: [PATCH 2/3] Removed unused var 'status', since it is not used in the returns any more --- proxy/hdrs/HdrTest.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/proxy/hdrs/HdrTest.cc b/proxy/hdrs/HdrTest.cc index 146e80dc614..53b5736e662 100644 --- a/proxy/hdrs/HdrTest.cc +++ b/proxy/hdrs/HdrTest.cc @@ -541,8 +541,6 @@ HdrTest::test_http_aux(const char *request, const char *response) const char *start; const char *end; - int status = 1; - printf(" <<< MUST BE HAND-VERIFIED FOR FULL BENEFIT >>>\n\n"); /*** (1) parse the request string into req_hdr ***/ @@ -1520,8 +1518,6 @@ HdrTest::test_http() int HdrTest::test_http_mutation() { - int status = 1; - bri_box("test_http_mutation"); printf(" <<< MUST BE HAND-VERIFIED FOR FULL BENEFIT>>>\n\n"); From 97bf944ff9eb3c95b6acc73e2bb60011c50d9651 Mon Sep 17 00:00:00 2001 From: ezelko260 Date: Tue, 28 Jan 2020 19:55:21 +0000 Subject: [PATCH 3/3] Remove substitution_count, no longer used --- proxy/http/remap/RemapConfig.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/proxy/http/remap/RemapConfig.cc b/proxy/http/remap/RemapConfig.cc index b3b1a467aba..ecba86328b9 100644 --- a/proxy/http/remap/RemapConfig.cc +++ b/proxy/http/remap/RemapConfig.cc @@ -845,7 +845,6 @@ process_regex_mapping_config(const char *from_host_lower, url_mapping *new_mappi const char *to_host; int to_host_len; int substitution_id; - int substitution_count = 0; int captures; reg_map->to_url_host_template = nullptr;