]> granicus.if.org Git - pdns/commitdiff
dnsdist: Don't shadow variables
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 20 Feb 2017 10:22:34 +0000 (11:22 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 20 Feb 2017 10:22:34 +0000 (11:22 +0100)
Fix shadowed variables reported by `-Wshadow`.

pdns/dnsdist-carbon.cc
pdns/dnsdist-console.cc
pdns/dnsdist-lua.cc
pdns/dnsdist-lua2.cc
pdns/dnsdist-web.cc
pdns/dnsdist.cc
pdns/dnsname.hh
pdns/test-dnsdistpacketcache_cc.cc

index 41f32c577e0ed1510d43d958b85d71dc9598ad3e..63e780d8259faff856d464cd797118e5f6dc9d55 100644 (file)
@@ -76,22 +76,22 @@ try
           str<<"dnsdist."<<hostname<<".main."<<e.first<<' ';
           if(const auto& val = boost::get<DNSDistStats::stat_t*>(&e.second))
             str<<(*val)->load();
-          else if (const auto& val = boost::get<double*>(&e.second))
-            str<<**val;
+          else if (const auto& dval = boost::get<double*>(&e.second))
+            str<<**dval;
           else
             str<<(*boost::get<DNSDistStats::statfunction_t>(&e.second))(e.first);
           str<<' '<<now<<"\r\n";
         }
         const auto states = g_dstates.getCopy();
-        for(const auto& s : states) {
-          string serverName = s->getName();
+        for(const auto& state : states) {
+          string serverName = state->getName();
           boost::replace_all(serverName, ".", "_");
           const string base = "dnsdist." + hostname + ".main.servers." + serverName + ".";
-          str<<base<<"queries" << ' ' << s->queries.load() << " " << now << "\r\n";
-          str<<base<<"drops" << ' ' << s->reuseds.load() << " " << now << "\r\n";
-          str<<base<<"latency" << ' ' << (s->availability != DownstreamState::Availability::Down ? s->latencyUsec/1000.0 : 0) << " " << now << "\r\n";
-          str<<base<<"senderrors" << ' ' << s->sendErrors.load() << " " << now << "\r\n";
-          str<<base<<"outstanding" << ' ' << s->outstanding.load() << " " << now << "\r\n";
+          str<<base<<"queries" << ' ' << state->queries.load() << " " << now << "\r\n";
+          str<<base<<"drops" << ' ' << state->reuseds.load() << " " << now << "\r\n";
+          str<<base<<"latency" << ' ' << (state->availability != DownstreamState::Availability::Down ? state->latencyUsec/1000.0 : 0) << " " << now << "\r\n";
+          str<<base<<"senderrors" << ' ' << state->sendErrors.load() << " " << now << "\r\n";
+          str<<base<<"outstanding" << ' ' << state->outstanding.load() << " " << now << "\r\n";
         }
         for(const auto& front : g_frontends) {
           if (front->udpFD == -1 && front->tcpFD == -1)
index f4dec4ad51e5a37130af132e75fe7a81638fc2c5..6ff39f88493b44a0a914e3642a874818a625e20f 100644 (file)
@@ -212,8 +212,8 @@ void doConsole()
             >
           >(withReturn ? ("return "+line) : line);
         if(ret) {
-          if (const auto strValue = boost::get<shared_ptr<DownstreamState>>(&*ret)) {
-            cout<<(*strValue)->getName()<<endl;
+          if (const auto dsValue = boost::get<shared_ptr<DownstreamState>>(&*ret)) {
+            cout<<(*dsValue)->getName()<<endl;
           }
           else if (const auto strValue = boost::get<string>(&*ret)) {
             cout<<*strValue<<endl;
@@ -253,17 +253,16 @@ void doConsole()
         std::rethrow_if_nested(e);
 
         std::cerr << std::endl;
-      } catch(const std::exception& e) {
-        // e is the exception that was thrown from inside the lambda
-        std::cerr << ": " << e.what() << std::endl;      
+      } catch(const std::exception& ne) {
+        // ne is the exception that was thrown from inside the lambda
+        std::cerr << ": " << ne.what() << std::endl;
       }
-      catch(const PDNSException& e) {
-        // e is the exception that was thrown from inside the lambda
-        std::cerr << ": " << e.reason << std::endl;      
+      catch(const PDNSException& ne) {
+        // ne is the exception that was thrown from inside the lambda
+        std::cerr << ": " << ne.reason << std::endl;
       }
     }
     catch(const std::exception& e) {
-      // e is the exception that was thrown from inside the lambda
       std::cerr << e.what() << std::endl;      
     }
   }
@@ -498,8 +497,8 @@ try
           >(withReturn ? ("return "+line) : line);
 
       if(ret) {
-       if (const auto strValue = boost::get<shared_ptr<DownstreamState>>(&*ret)) {
-         response=(*strValue)->getName()+"\n";
+       if (const auto dsValue = boost::get<shared_ptr<DownstreamState>>(&*ret)) {
+         response=(*dsValue)->getName()+"\n";
        }
        else if (const auto strValue = boost::get<string>(&*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) {
index 9ecc47e5e477e29f3d6a7e4cca6a3a99d9e5697a..6d12c0f30332207b8d6a429c1605c700df6f8e04 100644 (file)
@@ -366,8 +366,8 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
                        }
 
                        if(vars.count("qps")) {
-                         int qps=std::stoi(boost::get<string>(vars["qps"]));
-                         ret->qps=QPSLimiter(qps, qps);
+                         int qpsVal=std::stoi(boost::get<string>(vars["qps"]));
+                         ret->qps=QPSLimiter(qpsVal, qpsVal);
                        }
 
                        auto localPools = g_pools.getCopy();
@@ -1637,8 +1637,8 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
        string second;
        if(const auto& val = boost::get<DNSDistStats::stat_t*>(&e.second))
          second=std::to_string((*val)->load());
-       else if (const auto& val = boost::get<double*>(&e.second))
-         second=(flt % (**val)).str();
+       else if (const auto& dval = boost::get<double*>(&e.second))
+         second=(flt % (**dval)).str();
        else
          second=std::to_string((*boost::get<DNSDistStats::statfunction_t>(&e.second))(e.first));
 
index 1455b5a73454296ab4131b9e231657e0f09ed569..c9437c9dcc61703c989170617f7e739f7459a361 100644 (file)
@@ -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);
 
 }
 
index 530fc44012a13ee8c1f080a9687677a73bf20c70..88084a06ac5831feee70f8d9e32787cf978b6610 100644 (file)
@@ -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<DNSDistStats::stat_t*>(&e.second))
             obj.insert({e.first, (double)(*val)->load()});
-          else if (const auto& val = boost::get<double*>(&e.second))
-            obj.insert({e.first, (**val)});
+          else if (const auto& dval = boost::get<double*>(&e.second))
+            obj.insert({e.first, (**dval)});
           else
             obj.insert({e.first, (int)(*boost::get<DNSDistStats::statfunction_t>(&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<double*>(&item.second)) {
+        else if (const auto& dval = boost::get<double*>(&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<bool>(&item.second)) {
+        if (const auto& bval = boost::get<bool>(&item.second)) {
           doc.push_back(Json::object {
               { "type", "ConfigSetting" },
               { "name", item.first },
-              { "value", *val }
+              { "value", *bval }
           });
         }
-        else if (const auto& val = boost::get<string>(&item.second)) {
+        else if (const auto& sval = boost::get<string>(&item.second)) {
           doc.push_back(Json::object {
               { "type", "ConfigSetting" },
               { "name", item.first },
-              { "value", *val }
+              { "value", *sval }
           });
         }
-        else if (const auto& val = boost::get<double>(&item.second)) {
+        else if (const auto& dval = boost::get<double>(&item.second)) {
           doc.push_back(Json::object {
               { "type", "ConfigSetting" },
               { "name", item.first },
-              { "value", *val }
+              { "value", *dval }
           });
         }
       }
index eb5da3749515a65b21ede5b8b0241c8ca5588462..48f9a675452ac53f764ebbc31ff81fef4ce2898c 100644 (file)
@@ -600,7 +600,7 @@ shared_ptr<DownstreamState> valrandom(unsigned int val, const NumberedServerVect
     return shared_ptr<DownstreamState>();
 
   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<DownstreamState>();
   return p->second;
@@ -709,8 +709,8 @@ void addServerToPool(pools_t& pools, const string& poolName, std::shared_ptr<Dow
     });
   /* and now we need to renumber for Lua (custom policies) */
   size_t idx = 1;
-  for (auto& server : pool->servers) {
-    server.first = idx++;
+  for (auto& serv : pool->servers) {
+    serv.first = idx++;
   }
 }
 
index 4aa59913f352dabe19663b5a6efa6ad2874d09a0..7b89f0b62321ad1ab0e0ae7aeca5726237b94065 100644 (file)
@@ -300,23 +300,23 @@ struct SuffixMatchNode
 template<typename T>
 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<SuffixMatchTree> 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;
 
index 712ae5b2fca1b483fa217aa5665075e2efb2bf5e..4a944536e0d7217987cdb0bc36e7667044a5b19d 100644 (file)
@@ -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<uint8_t> 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<DNSResourceRecord> entry;
     ComboAddress remote;
     for(unsigned int counter=0; counter < 100000; ++counter) {