This is an automated email from the ASF dual-hosted git repository. zwoop pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/9.0.x by this push: new 44b220d Fixing shadowed variables, both global and local: (#6371) 44b220d is described below commit 44b220d652b74af0b5f3a47acad374766ebcee67 Author: Evan Zelkowitz <e...@apache.org> AuthorDate: Wed Jan 29 13:56:21 2020 -0700 Fixing shadowed variables, both global and local: (#6371) https://lgtm.com/projects/g/apache/trafficserver/?mode=tree&ruleFocus=2157860312 https://lgtm.com/projects/g/apache/trafficserver/?mode=tree&ruleFocus=2156240606 Addresses issue #6352 (cherry picked from commit 2e1202023219457496c2cc49d199f20fc79d5796) --- iocore/hostdb/HostDB.cc | 4 +- iocore/net/SSLUtils.cc | 12 +++--- iocore/net/UnixNetAccept.cc | 6 +-- plugins/background_fetch/background_fetch.cc | 4 +- plugins/experimental/memcache/tsmemcache.cc | 8 ++-- plugins/header_rewrite/conditions.cc | 16 +++---- plugins/multiplexer/dispatch.cc | 6 +-- src/traffic_cache_tool/CacheTool.cc | 10 ++--- src/traffic_logcat/logcat.cc | 12 +++--- src/traffic_server/InkAPI.cc | 10 ++--- src/traffic_server/traffic_server.cc | 18 ++++---- src/tscore/IpMap.cc | 62 ++++++++++++++-------------- tools/jtest/jtest.cc | 8 ++-- 13 files changed, 88 insertions(+), 88 deletions(-) diff --git a/iocore/hostdb/HostDB.cc b/iocore/hostdb/HostDB.cc index 045593c..3e6aaad 100644 --- a/iocore/hostdb/HostDB.cc +++ b/iocore/hostdb/HostDB.cc @@ -2216,7 +2216,7 @@ ParseHostLine(Ptr<RefCountedHostsFileMap> &map, char *l) } void -ParseHostFile(const char *path, unsigned int hostdb_hostfile_check_interval) +ParseHostFile(const char *path, unsigned int hostdb_hostfile_check_interval_parse) { Ptr<RefCountedHostsFileMap> parsed_hosts_file_ptr; @@ -2236,7 +2236,7 @@ ParseHostFile(const char *path, unsigned int hostdb_hostfile_check_interval) int64_t size = info.st_size + 1; parsed_hosts_file_ptr = new RefCountedHostsFileMap; - parsed_hosts_file_ptr->next_sync_time = ink_time() + hostdb_hostfile_check_interval; + parsed_hosts_file_ptr->next_sync_time = ink_time() + hostdb_hostfile_check_interval_parse; parsed_hosts_file_ptr->HostFileText = static_cast<char *>(ats_malloc(size)); if (parsed_hosts_file_ptr->HostFileText) { char *base = parsed_hosts_file_ptr->HostFileText; diff --git a/iocore/net/SSLUtils.cc b/iocore/net/SSLUtils.cc index 1e6c09a..54cc5e8 100644 --- a/iocore/net/SSLUtils.cc +++ b/iocore/net/SSLUtils.cc @@ -1737,10 +1737,10 @@ SSLWriteBuffer(SSL *ssl, const void *buf, int64_t nbytes, int64_t &nwritten) } int ssl_error = SSL_get_error(ssl, ret); if (ssl_error == SSL_ERROR_SSL && is_debug_tag_set("ssl.error.write")) { - char buf[512]; + char tempbuf[512]; unsigned long e = ERR_peek_last_error(); - ERR_error_string_n(e, buf, sizeof(buf)); - Debug("ssl.error.write", "SSL write returned %d, ssl_error=%d, ERR_get_error=%ld (%s)", ret, ssl_error, e, buf); + ERR_error_string_n(e, tempbuf, sizeof(tempbuf)); + Debug("ssl.error.write", "SSL write returned %d, ssl_error=%d, ERR_get_error=%ld (%s)", ret, ssl_error, e, tempbuf); } return ssl_error; } @@ -1818,10 +1818,10 @@ SSLReadBuffer(SSL *ssl, void *buf, int64_t nbytes, int64_t &nread) } int ssl_error = SSL_get_error(ssl, ret); if (ssl_error == SSL_ERROR_SSL && is_debug_tag_set("ssl.error.read")) { - char buf[512]; + char tempbuf[512]; unsigned long e = ERR_peek_last_error(); - ERR_error_string_n(e, buf, sizeof(buf)); - Debug("ssl.error.read", "SSL read returned %d, ssl_error=%d, ERR_get_error=%ld (%s)", ret, ssl_error, e, buf); + ERR_error_string_n(e, tempbuf, sizeof(tempbuf)); + Debug("ssl.error.read", "SSL read returned %d, ssl_error=%d, ERR_get_error=%ld (%s)", ret, ssl_error, e, tempbuf); } return ssl_error; diff --git a/iocore/net/UnixNetAccept.cc b/iocore/net/UnixNetAccept.cc index 9254d7f..7109a27 100644 --- a/iocore/net/UnixNetAccept.cc +++ b/iocore/net/UnixNetAccept.cc @@ -356,11 +356,11 @@ NetAccept::do_blocking_accept(EThread *t) #endif SET_CONTINUATION_HANDLER(vc, (NetVConnHandler)&UnixNetVConnection::acceptEvent); - EThread *t = eventProcessor.assign_thread(opt.etype); - NetHandler *h = get_NetHandler(t); + EThread *localt = eventProcessor.assign_thread(opt.etype); + NetHandler *h = get_NetHandler(localt); // Assign NetHandler->mutex to NetVC vc->mutex = h->mutex; - t->schedule_imm_signal(vc); + localt->schedule_imm_signal(vc); } while (loop); return 1; diff --git a/plugins/background_fetch/background_fetch.cc b/plugins/background_fetch/background_fetch.cc index fbeba7d..13aaff4 100644 --- a/plugins/background_fetch/background_fetch.cc +++ b/plugins/background_fetch/background_fetch.cc @@ -531,9 +531,9 @@ cont_handle_response(TSCont contp, TSEvent event, void *edata) TSDebug(PLUGIN_NAME, "Testing: response status code: %d?", status); if (TS_HTTP_STATUS_PARTIAL_CONTENT == status || (config->allow304() && TS_HTTP_STATUS_NOT_MODIFIED == status)) { // Everything looks good so far, add a TXN hook for SEND_RESPONSE_HDR - TSCont contp = TSContCreate(cont_check_cacheable, nullptr); + TSCont localcontp = TSContCreate(cont_check_cacheable, nullptr); - TSHttpTxnHookAdd(txnp, TS_HTTP_SEND_RESPONSE_HDR_HOOK, contp); + TSHttpTxnHookAdd(txnp, TS_HTTP_SEND_RESPONSE_HDR_HOOK, localcontp); } // Release the response MLoc TSHandleMLocRelease(response, TS_NULL_MLOC, resp_hdr); diff --git a/plugins/experimental/memcache/tsmemcache.cc b/plugins/experimental/memcache/tsmemcache.cc index bdb2ebe..1214934 100644 --- a/plugins/experimental/memcache/tsmemcache.cc +++ b/plugins/experimental/memcache/tsmemcache.cc @@ -962,13 +962,13 @@ MC::ascii_incr_decr_event(int event, void *data) } header.cas = ink_atomic_increment(&next_cas, 1); { - char *data = nullptr; - int len = 0; + char *localdata = nullptr; + int len = 0; // must be huge, why convert to a counter ?? - if (cwvc->get_single_data((void **)&data, &len) < 0) { + if (cwvc->get_single_data((void **)&localdata, &len) < 0) { goto Lfail; } - uint64_t new_value = xatoull(data, data + len); + uint64_t new_value = xatoull(localdata, localdata + len); if (f.set_incr) { new_value += delta; } else { diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc index 380d270..8bb3848 100644 --- a/plugins/header_rewrite/conditions.cc +++ b/plugins/header_rewrite/conditions.cc @@ -1113,17 +1113,17 @@ ConditionCidr::append_value(std::string &s, const Resources &res) if (addr) { switch (addr->sa_family) { case AF_INET: { - char res[INET_ADDRSTRLEN]; + char resource[INET_ADDRSTRLEN]; struct in_addr ipv4 = reinterpret_cast<const struct sockaddr_in *>(addr)->sin_addr; ipv4.s_addr &= _v4_mask.s_addr; - inet_ntop(AF_INET, &ipv4, res, INET_ADDRSTRLEN); - if (res[0]) { - s += res; + inet_ntop(AF_INET, &ipv4, resource, INET_ADDRSTRLEN); + if (resource[0]) { + s += resource; } } break; case AF_INET6: { - char res[INET6_ADDRSTRLEN]; + char resource[INET6_ADDRSTRLEN]; struct in6_addr ipv6 = reinterpret_cast<const struct sockaddr_in6 *>(addr)->sin6_addr; if (_v6_zero_bytes > 0) { @@ -1132,9 +1132,9 @@ ConditionCidr::append_value(std::string &s, const Resources &res) if (_v6_mask != 0xff) { ipv6.s6_addr[16 - _v6_zero_bytes] &= _v6_mask; } - inet_ntop(AF_INET6, &ipv6, res, INET6_ADDRSTRLEN); - if (res[0]) { - s += res; + inet_ntop(AF_INET6, &ipv6, resource, INET6_ADDRSTRLEN); + if (resource[0]) { + s += resource; } } break; } diff --git a/plugins/multiplexer/dispatch.cc b/plugins/multiplexer/dispatch.cc index 675b23a..d5f4c3a 100644 --- a/plugins/multiplexer/dispatch.cc +++ b/plugins/multiplexer/dispatch.cc @@ -168,9 +168,9 @@ public: if (TSIsDebugTagSet(PLUGIN_TAG) > 0) { const TSIOBuffer buffer = TSIOBufferCreate(); TSHttpHdrPrint(b, l, buffer); - std::string b; - read(buffer, b); - TSDebug(PLUGIN_TAG, "Response header for \"%s\" was:\n%s", url.c_str(), b.c_str()); + std::string buf; + read(buffer, buf); + TSDebug(PLUGIN_TAG, "Response header for \"%s\" was:\n%s", url.c_str(), buf.c_str()); TSIOBufferDestroy(buffer); } } diff --git a/src/traffic_cache_tool/CacheTool.cc b/src/traffic_cache_tool/CacheTool.cc index c5b56d7..4a68d6d 100644 --- a/src/traffic_cache_tool/CacheTool.cc +++ b/src/traffic_cache_tool/CacheTool.cc @@ -520,8 +520,8 @@ Cache::loadSpanConfig(ts::file::path const &path) if (line.empty() || '#' == *line) { continue; } - ts::TextView path = line.take_prefix_if(&isspace); - if (path) { + ts::TextView localpath = line.take_prefix_if(&isspace); + if (localpath) { // After this the line is [size] [id=string] [volume=#] while (line) { ts::TextView value(line.take_prefix_if(&isspace)); @@ -539,7 +539,7 @@ Cache::loadSpanConfig(ts::file::path const &path) } } } - zret = this->loadSpan(ts::file::path(path)); + zret = this->loadSpan(ts::file::path(localpath)); } } } else { @@ -552,7 +552,7 @@ Errata Cache::loadURLs(ts::file::path const &path) { static const ts::TextView TAG_VOL("url"); - ts::URLparser parser; + ts::URLparser loadURLparser; Errata zret; std::error_code ec; @@ -568,7 +568,7 @@ Cache::loadURLs(ts::file::path const &path) std::string url; url.assign(blob.data(), blob.size()); int port_ptr = -1, port_len = -1; - int port = parser.getPort(url, port_ptr, port_len); + int port = loadURLparser.getPort(url, port_ptr, port_len); if (port_ptr >= 0 && port_len > 0) { url.erase(port_ptr, port_len + 1); // get rid of :PORT } diff --git a/src/traffic_logcat/logcat.cc b/src/traffic_logcat/logcat.cc index debbaf0..5ac69aa 100644 --- a/src/traffic_logcat/logcat.cc +++ b/src/traffic_logcat/logcat.cc @@ -208,14 +208,14 @@ process_file(int in_fd, int out_fd) } static int -open_output_file(char *output_file) +open_output_file(char *output_file_p) { int file_desc = 0; if (!overwrite_existing_file) { - if (access(output_file, F_OK)) { + if (access(output_file_p, F_OK)) { if (errno != ENOENT) { - fprintf(stderr, "Error accessing output file %s: ", output_file); + fprintf(stderr, "Error accessing output file %s: ", output_file_p); perror(nullptr); file_desc = -1; } @@ -223,16 +223,16 @@ open_output_file(char *output_file) fprintf(stderr, "Error, output file %s already exists.\n" "Select a different filename or use the -w flag\n", - output_file); + output_file_p); file_desc = -1; } } if (file_desc == 0) { - file_desc = open(output_file, O_WRONLY | O_TRUNC | O_CREAT, 0640); + file_desc = open(output_file_p, O_WRONLY | O_TRUNC | O_CREAT, 0640); if (file_desc < 0) { - fprintf(stderr, "Error while opening output file %s: ", output_file); + fprintf(stderr, "Error while opening output file %s: ", output_file_p); perror(nullptr); } } diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc index bea515b..d53f679 100644 --- a/src/traffic_server/InkAPI.cc +++ b/src/traffic_server/InkAPI.cc @@ -6817,19 +6817,19 @@ TSHttpConnectTransparent(sockaddr const *client_addr, sockaddr const *server_add void TSActionCancel(TSAction actionp) { - Action *a; + Action *thisaction; INKContInternal *i; /* This is a hack. Should be handled in ink_types */ if ((uintptr_t)actionp & 0x1) { - a = (Action *)((uintptr_t)actionp - 1); - i = (INKContInternal *)a->continuation; + thisaction = (Action *)((uintptr_t)actionp - 1); + i = (INKContInternal *)thisaction->continuation; i->handle_event_count(EVENT_IMMEDIATE); } else { - a = (Action *)actionp; + thisaction = (Action *)actionp; } - a->cancel(); + thisaction->cancel(); } // Currently no error handling necessary, actionp can be anything. diff --git a/src/traffic_server/traffic_server.cc b/src/traffic_server/traffic_server.cc index dc1e361..afb72fc 100644 --- a/src/traffic_server/traffic_server.cc +++ b/src/traffic_server/traffic_server.cc @@ -1635,27 +1635,27 @@ change_uid_gid(const char *user) * This must work without the ability to elevate privilege if the files are accessible without. */ void -bind_outputs(const char *bind_stdout, const char *bind_stderr) +bind_outputs(const char *bind_stdout_p, const char *bind_stderr_p) { int log_fd; unsigned int flags = O_WRONLY | O_APPEND | O_CREAT | O_SYNC; - if (*bind_stdout != 0) { - Debug("log", "binding stdout to %s", bind_stdout); - log_fd = elevating_open(bind_stdout, flags, 0644); + if (*bind_stdout_p != 0) { + Debug("log", "binding stdout to %s", bind_stdout_p); + log_fd = elevating_open(bind_stdout_p, flags, 0644); if (log_fd < 0) { - fprintf(stdout, "[Warning]: TS unable to open log file \"%s\" [%d '%s']\n", bind_stdout, errno, strerror(errno)); + fprintf(stdout, "[Warning]: TS unable to open log file \"%s\" [%d '%s']\n", bind_stdout_p, errno, strerror(errno)); } else { Debug("log", "duping stdout"); dup2(log_fd, STDOUT_FILENO); close(log_fd); } } - if (*bind_stderr != 0) { - Debug("log", "binding stderr to %s", bind_stderr); - log_fd = elevating_open(bind_stderr, O_WRONLY | O_APPEND | O_CREAT | O_SYNC, 0644); + if (*bind_stderr_p != 0) { + Debug("log", "binding stderr to %s", bind_stderr_p); + log_fd = elevating_open(bind_stderr_p, O_WRONLY | O_APPEND | O_CREAT | O_SYNC, 0644); if (log_fd < 0) { - fprintf(stdout, "[Warning]: TS unable to open log file \"%s\" [%d '%s']\n", bind_stderr, errno, strerror(errno)); + fprintf(stdout, "[Warning]: TS unable to open log file \"%s\" [%d '%s']\n", bind_stderr_p, errno, strerror(errno)); } else { Debug("log", "duping stderr"); dup2(log_fd, STDERR_FILENO); diff --git a/src/tscore/IpMap.cc b/src/tscore/IpMap.cc index 3001fc1..481ea03 100644 --- a/src/tscore/IpMap.cc +++ b/src/tscore/IpMap.cc @@ -339,22 +339,22 @@ namespace detail N *n = this->lowerBound(rmin); N *x = nullptr; // New node (if any). // Need copies because we will modify these. - Metric min = N::deref(rmin); - Metric max = N::deref(rmax); + Metric localmin = N::deref(rmin); + Metric localmax = N::deref(rmax); // Handle cases involving a node of interest to the left of the // range. if (n) { - if (n->_min < min) { - Metric min_1 = min; + if (n->_min < localmin) { + Metric min_1 = localmin; N::dec(min_1); // dec is OK because min isn't zero. if (n->_max < min_1) { // no overlap or adj. n = next(n); - } else if (n->_max >= max) { // incoming range is covered, just discard. + } else if (n->_max >= localmax) { // incoming range is covered, just discard. return *this; } else if (n->_data != payload) { // different payload, clip range on left. - min = n->_max; - N::inc(min); + localmin = n->_max; + N::inc(localmin); n = next(n); } else { // skew overlap with same payload, use node and continue. x = n; @@ -371,7 +371,7 @@ namespace detail // Careful here -- because max_plus1 might wrap we need to use it only if we can be certain it // didn't. This is done by ordering the range tests so that when max_plus1 is used when we know // there exists a larger value than max. - Metric max_plus1 = max; + Metric max_plus1 = localmax; N::inc(max_plus1); /* Notes: @@ -381,7 +381,7 @@ namespace detail while (n) { if (n->_data == payload) { if (x) { - if (n->_max <= max) { // next range is covered, so we can remove and continue. + if (n->_max <= localmax) { // next range is covered, so we can remove and continue. #if defined(__clang_analyzer__) x->_next = n->_next; // done in @c remove, but CA doesn't realize that. // It's insufficient to assert(x->_next != n) after the remove. @@ -395,52 +395,52 @@ namespace detail return *this; } else { // have the space to finish off the range. - x->setMax(max); + x->setMax(localmax); return *this; } - } else { // not carrying a span. - if (n->_max <= max) { // next range is covered - use it. + } else { // not carrying a span. + if (n->_max <= localmax) { // next range is covered - use it. x = n; - x->setMin(min); + x->setMin(localmin); n = next(n); } else if (n->_min <= max_plus1) { - n->setMin(min); + n->setMin(localmin); return *this; } else { // no overlap, space to complete range. - this->insert_before(n, new N(min, max, payload)); + this->insert_before(n, new N(localmin, localmax, payload)); return *this; } } } else { // different payload if (x) { - if (max < n->_min) { // range ends before n starts, done. - x->setMax(max); + if (localmax < n->_min) { // range ends before n starts, done. + x->setMax(localmax); return *this; - } else if (max <= n->_max) { // range ends before n, done. + } else if (localmax <= n->_max) { // range ends before n, done. x->setMaxMinusOne(n->_min); return *this; } else { // n is contained in range, skip over it. x->setMaxMinusOne(n->_min); - x = nullptr; - min = n->_max; - N::inc(min); // OK because n->_max maximal => next is null. + x = nullptr; + localmin = n->_max; + N::inc(localmin); // OK because n->_max maximal => next is null. n = next(n); } - } else { // no carry node. - if (max < n->_min) { // entirely before next span. - this->insert_before(n, new N(min, max, payload)); + } else { // no carry node. + if (localmax < n->_min) { // entirely before next span. + this->insert_before(n, new N(localmin, localmax, payload)); return *this; } else { - if (min < n->_min) { // leading section, need node. - N *y = new N(min, n->_min, payload); + if (localmin < n->_min) { // leading section, need node. + N *y = new N(localmin, n->_min, payload); y->decrementMax(); this->insert_before(n, y); } - if (max <= n->_max) { // nothing past node + if (localmax <= n->_max) { // nothing past node return *this; } - min = n->_max; - N::inc(min); + localmin = n->_max; + N::inc(localmin); n = next(n); } } @@ -448,9 +448,9 @@ namespace detail } // Invariant: min is larger than any existing range maximum. if (x) { - x->setMax(max); + x->setMax(localmax); } else { - this->append(new N(min, max, payload)); + this->append(new N(localmin, localmax, payload)); } return *this; } diff --git a/tools/jtest/jtest.cc b/tools/jtest/jtest.cc index b856469..fa96f4e 100644 --- a/tools/jtest/jtest.cc +++ b/tools/jtest/jtest.cc @@ -569,11 +569,11 @@ max_limit_fd() } static int -read_ready(int fd) +read_ready(int fd_in) { struct pollfd p; p.events = POLLIN; - p.fd = fd; + p.fd = fd_in; int r = poll(&p, 1, 0); if (r <= 0) { return r; @@ -646,8 +646,8 @@ fast(int sock, int speed, int d) static ink_hrtime elapsed_from_start(int sock) { - ink_hrtime now = ink_get_hrtime_internal(); - return ink_hrtime_diff_msec(now, fd[sock].start); + ink_hrtime timenow = ink_get_hrtime_internal(); + return ink_hrtime_diff_msec(timenow, fd[sock].start); } static int