TS-898: remove pointless NULL check on array cl.origin_list is an array do the NULL check is pointless. Also simplify the code around origiin set initialization so that the origin set is always allocated. Coverity #1200013.
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/b90a731d Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/b90a731d Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/b90a731d Branch: refs/heads/5.0.x Commit: b90a731d4e2d31fbb1e958bde76250a3994fb690 Parents: d3b6c11 Author: James Peach <[email protected]> Authored: Sun Apr 13 17:00:18 2014 -0700 Committer: James Peach <[email protected]> Committed: Sun Apr 13 17:04:34 2014 -0700 ---------------------------------------------------------------------- CHANGES | 2 ++ proxy/logstats.cc | 22 ++++++++-------------- 2 files changed, 10 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b90a731d/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 4970f8e..93b67d0 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ -*- coding: utf-8 -*- Changes with Apache Traffic Server 5.0.0 + *) [TS-898] Remove pointless NULL check on address of array. + *) [TS-898] Avoid passing -1 to close (2) in traffic_cop. *) [TS-898] Fix minor regex_remap parsing bug. http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b90a731d/proxy/logstats.cc ---------------------------------------------------------------------- diff --git a/proxy/logstats.cc b/proxy/logstats.cc index f3249ef..15aeaa2 100644 --- a/proxy/logstats.cc +++ b/proxy/logstats.cc @@ -1372,7 +1372,7 @@ parse_log_buff(LogBufferHeader * buf_header, bool summary = false) // TODO: If we save state (struct) for a run, we probably need to always // update the origin data, no matter what the origin_set is. - if (origin_set ? (origin_set->find(tok) != origin_set->end()) : 1) { + if (origin_set->empty() || (origin_set->find(tok) != origin_set->end())) { o_iter = origins.find(tok); if (origins.end() == o_iter) { o_stats = (OriginStats *)ats_malloc(sizeof(OriginStats)); @@ -2189,7 +2189,7 @@ my_exit(const ExitStatus& status) } // Next the totals for all Origins, unless we specified a list of origins to filter. - if (!origin_set) { + if (origin_set->empty()) { first = false; if (cl.json) { std::cout << "{ \"total\": {" << std::endl; @@ -2284,7 +2284,7 @@ main(int /* argc ATS_UNUSED */, char *argv[]) memset(&totals, 0, sizeof(totals)); init_elapsed(&totals); - origin_set = NULL; + origin_set = NEW(new OriginSet); parse_errors = 0; // Command line parsing @@ -2309,13 +2309,9 @@ main(int /* argc ATS_UNUSED */, char *argv[]) char *tok; char *sep_ptr; - if (NULL == origin_set) - origin_set = NEW(new OriginSet); - if (cl.origin_list) { - for (tok = strtok_r(cl.origin_list, ",", &sep_ptr); tok != NULL;) { - origin_set->insert(tok); - tok = strtok_r(NULL, ",", &sep_ptr); - } + for (tok = strtok_r(cl.origin_list, ",", &sep_ptr); tok != NULL;) { + origin_set->insert(tok); + tok = strtok_r(NULL, ",", &sep_ptr); } } // Load origins from an "external" file (\n separated) @@ -2329,9 +2325,6 @@ main(int /* argc ATS_UNUSED */, char *argv[]) _exit(0); } - if (NULL == origin_set) - origin_set = NEW(new OriginSet); - while (!fs.eof()) { std::string line; std::string::size_type start, end; @@ -2347,8 +2340,9 @@ main(int /* argc ATS_UNUSED */, char *argv[]) char *buf; buf = ats_strdup(line.substr(start, end).c_str()); - if (buf) + if (buf) { origin_set->insert(buf); + } } } }
