From: Remi Gacogne Date: Mon, 20 Feb 2017 10:22:34 +0000 (+0100) Subject: dnsdist: Don't shadow variables X-Git-Tag: rec-4.1.0-alpha1~265^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=af619119f9bde7020f74c1b20cda5c91b1a91bde;p=pdns dnsdist: Don't shadow variables Fix shadowed variables reported by `-Wshadow`. --- diff --git a/pdns/dnsdist-carbon.cc b/pdns/dnsdist-carbon.cc index 41f32c577..63e780d82 100644 --- a/pdns/dnsdist-carbon.cc +++ b/pdns/dnsdist-carbon.cc @@ -76,22 +76,22 @@ try str<<"dnsdist."<(&e.second)) str<<(*val)->load(); - else if (const auto& val = boost::get(&e.second)) - str<<**val; + else if (const auto& dval = boost::get(&e.second)) + str<<**dval; else str<<(*boost::get(&e.second))(e.first); str<<' '<getName(); + for(const auto& state : states) { + string serverName = state->getName(); boost::replace_all(serverName, ".", "_"); const string base = "dnsdist." + hostname + ".main.servers." + serverName + "."; - str<queries.load() << " " << now << "\r\n"; - str<reuseds.load() << " " << now << "\r\n"; - str<availability != DownstreamState::Availability::Down ? s->latencyUsec/1000.0 : 0) << " " << now << "\r\n"; - str<sendErrors.load() << " " << now << "\r\n"; - str<outstanding.load() << " " << now << "\r\n"; + str<queries.load() << " " << now << "\r\n"; + str<reuseds.load() << " " << now << "\r\n"; + str<availability != DownstreamState::Availability::Down ? state->latencyUsec/1000.0 : 0) << " " << now << "\r\n"; + str<sendErrors.load() << " " << now << "\r\n"; + str<outstanding.load() << " " << now << "\r\n"; } for(const auto& front : g_frontends) { if (front->udpFD == -1 && front->tcpFD == -1) diff --git a/pdns/dnsdist-console.cc b/pdns/dnsdist-console.cc index f4dec4ad5..6ff39f884 100644 --- a/pdns/dnsdist-console.cc +++ b/pdns/dnsdist-console.cc @@ -212,8 +212,8 @@ void doConsole() > >(withReturn ? ("return "+line) : line); if(ret) { - if (const auto strValue = boost::get>(&*ret)) { - cout<<(*strValue)->getName()<>(&*ret)) { + cout<<(*dsValue)->getName()<(&*ret)) { cout<<*strValue<(withReturn ? ("return "+line) : line); if(ret) { - if (const auto strValue = boost::get>(&*ret)) { - response=(*strValue)->getName()+"\n"; + if (const auto dsValue = boost::get>(&*ret)) { + response=(*dsValue)->getName()+"\n"; } else if (const auto strValue = boost::get(&*ret)) { response=*strValue+"\n"; @@ -537,13 +536,13 @@ try response = "Error: " + string(e.what()); try { std::rethrow_if_nested(e); - } catch(const std::exception& e) { - // e is the exception that was thrown from inside the lambda - response+= ": " + string(e.what()); + } catch(const std::exception& ne) { + // ne is the exception that was thrown from inside the lambda + response+= ": " + string(ne.what()); } - catch(const PDNSException& e) { - // e is the exception that was thrown from inside the lambda - response += ": " + string(e.reason); + catch(const PDNSException& ne) { + // ne is the exception that was thrown from inside the lambda + response += ": " + string(ne.reason); } } catch(const LuaContext::SyntaxErrorException& e) { diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 9ecc47e5e..6d12c0f30 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -366,8 +366,8 @@ vector> setupLua(bool client, const std::string& confi } if(vars.count("qps")) { - int qps=std::stoi(boost::get(vars["qps"])); - ret->qps=QPSLimiter(qps, qps); + int qpsVal=std::stoi(boost::get(vars["qps"])); + ret->qps=QPSLimiter(qpsVal, qpsVal); } auto localPools = g_pools.getCopy(); @@ -1637,8 +1637,8 @@ vector> setupLua(bool client, const std::string& confi string second; if(const auto& val = boost::get(&e.second)) second=std::to_string((*val)->load()); - else if (const auto& val = boost::get(&e.second)) - second=(flt % (**val)).str(); + else if (const auto& dval = boost::get(&e.second)) + second=(flt % (**dval)).str(); else second=std::to_string((*boost::get(&e.second))(e.first)); diff --git a/pdns/dnsdist-lua2.cc b/pdns/dnsdist-lua2.cc index 1455b5a73..c9437c9dc 100644 --- a/pdns/dnsdist-lua2.cc +++ b/pdns/dnsdist-lua2.cc @@ -109,8 +109,8 @@ static void statNodeRespRing(statvisitor_t visitor, unsigned int seconds) } StatNode::Stat node; - root.visit([&visitor](const StatNode* node, const StatNode::Stat& self, const StatNode::Stat& children) { - visitor(*node, self, children);}, node); + root.visit([&visitor](const StatNode* node_, const StatNode::Stat& self, const StatNode::Stat& children) { + visitor(*node_, self, children);}, node); } diff --git a/pdns/dnsdist-web.cc b/pdns/dnsdist-web.cc index 530fc4401..88084a06a 100644 --- a/pdns/dnsdist-web.cc +++ b/pdns/dnsdist-web.cc @@ -251,8 +251,8 @@ static void connectionThread(int sock, ComboAddress remote, string password, str for(const auto& e : g_stats.entries) { if(const auto& val = boost::get(&e.second)) obj.insert({e.first, (double)(*val)->load()}); - else if (const auto& val = boost::get(&e.second)) - obj.insert({e.first, (**val)}); + else if (const auto& dval = boost::get(&e.second)) + obj.insert({e.first, (**dval)}); else obj.insert({e.first, (int)(*boost::get(&e.second))(e.first)}); } @@ -445,11 +445,11 @@ static void connectionThread(int sock, ComboAddress remote, string password, str { "value", (double)(*val)->load() } }); } - else if (const auto& val = boost::get(&item.second)) { + else if (const auto& dval = boost::get(&item.second)) { doc.push_back(Json::object { { "type", "StatisticItem" }, { "name", item.first }, - { "value", (**val) } + { "value", (**dval) } }); } else { @@ -487,25 +487,25 @@ static void connectionThread(int sock, ComboAddress remote, string password, str { "verbose-health-checks", g_verboseHealthChecks } }; for(const auto& item : configEntries) { - if (const auto& val = boost::get(&item.second)) { + if (const auto& bval = boost::get(&item.second)) { doc.push_back(Json::object { { "type", "ConfigSetting" }, { "name", item.first }, - { "value", *val } + { "value", *bval } }); } - else if (const auto& val = boost::get(&item.second)) { + else if (const auto& sval = boost::get(&item.second)) { doc.push_back(Json::object { { "type", "ConfigSetting" }, { "name", item.first }, - { "value", *val } + { "value", *sval } }); } - else if (const auto& val = boost::get(&item.second)) { + else if (const auto& dval = boost::get(&item.second)) { doc.push_back(Json::object { { "type", "ConfigSetting" }, { "name", item.first }, - { "value", *val } + { "value", *dval } }); } } diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index eb5da3749..48f9a6754 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -600,7 +600,7 @@ shared_ptr valrandom(unsigned int val, const NumberedServerVect return shared_ptr(); int r = val % sum; - auto p = upper_bound(poss.begin(), poss.end(),r, [](int r, const decltype(poss)::value_type& a) { return r < a.first;}); + auto p = upper_bound(poss.begin(), poss.end(),r, [](int r_, const decltype(poss)::value_type& a) { return r_ < a.first;}); if(p==poss.end()) return shared_ptr(); return p->second; @@ -709,8 +709,8 @@ void addServerToPool(pools_t& pools, const string& poolName, std::shared_ptrservers) { - server.first = idx++; + for (auto& serv : pool->servers) { + serv.first = idx++; } } diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index 4aa59913f..7b89f0b62 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -300,23 +300,23 @@ struct SuffixMatchNode template struct SuffixMatchTree { - SuffixMatchTree(const std::string& name_="", bool endNode_=false) : name(name_), endNode(endNode_) + SuffixMatchTree(const std::string& name="", bool endNode_=false) : d_name(name), endNode(endNode_) {} SuffixMatchTree(const SuffixMatchTree& rhs) { - name = rhs.name; + d_name = rhs.d_name; children = rhs.children; endNode = rhs.endNode; d_value = rhs.d_value; } - std::string name; + std::string d_name; mutable std::set children; mutable bool endNode; mutable T d_value; bool operator<(const SuffixMatchTree& rhs) const { - return strcasecmp(name.c_str(), rhs.name.c_str()) < 0; + return strcasecmp(d_name.c_str(), rhs.d_name.c_str()) < 0; } typedef SuffixMatchTree value_type; diff --git a/pdns/test-dnsdistpacketcache_cc.cc b/pdns/test-dnsdistpacketcache_cc.cc index 712ae5b2f..4a944536e 100644 --- a/pdns/test-dnsdistpacketcache_cc.cc +++ b/pdns/test-dnsdistpacketcache_cc.cc @@ -107,11 +107,11 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheSimple) { static DNSDistPacketCache PC(500000); -static void *threadMangler(void* a) +static void *threadMangler(void* off) { try { ComboAddress remote; - unsigned int offset=(unsigned int)(unsigned long)a; + unsigned int offset=(unsigned int)(unsigned long)off; for(unsigned int counter=0; counter < 100000; ++counter) { DNSName a=DNSName("hello ")+DNSName(std::to_string(counter+offset)); vector query; @@ -147,11 +147,11 @@ static void *threadMangler(void* a) AtomicCounter g_missing; -static void *threadReader(void* a) +static void *threadReader(void* off) { try { - unsigned int offset=(unsigned int)(unsigned long)a; + unsigned int offset=(unsigned int)(unsigned long)off; vector entry; ComboAddress remote; for(unsigned int counter=0; counter < 100000; ++counter) {