]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Fix static analysis warnings
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 24 Jun 2024 07:44:42 +0000 (09:44 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 15 Jul 2024 09:47:59 +0000 (11:47 +0200)
pdns/dnsdistdist/dnsdist-carbon.cc
pdns/dnsdistdist/dnsdist-lbpolicies.cc
pdns/dnsdistdist/dnsdist-lua-ffi.cc
pdns/dnsdistdist/dnsdist-lua.cc
pdns/dnsdistdist/dnsdist-snmp.cc
pdns/dnsdistdist/dnsdist.cc
pdns/dnsdistdist/test-dnsdistdynblocks_hh.cc
pdns/dnsdistdist/test-dnsdistlbpolicies_cc.cc

index 5df2049352d2bcf6acbf3960945ccf9b9b58f0b6..ee396d0452c54da1b66ae8737e1ceb2fc73fefdb 100644 (file)
@@ -296,7 +296,7 @@ static bool doOneCarbonExport(const Carbon::Endpoint& endpoint)
   return true;
 }
 
-static void carbonHandler(Carbon::Endpoint endpoint)
+static void carbonHandler(const Carbon::Endpoint& endpoint)
 {
   setThreadName("dnsdist/carbon");
   const auto intervalUSec = endpoint.interval * 1000 * 1000;
@@ -356,7 +356,7 @@ Carbon::Endpoint Carbon::newEndpoint(const std::string& address, std::string our
 
 void Carbon::run(const std::vector<Carbon::Endpoint>& endpoints)
 {
-  for (auto& endpoint : endpoints) {
+  for (const auto& endpoint : endpoints) {
     std::thread newHandler(carbonHandler, endpoint);
     newHandler.detach();
   }
index 31d772ddb25f129720a18f3ffbed9f98ec05288a..a648435a0a0d6d38443a4bbec4830dba10bd7a3e 100644 (file)
@@ -184,7 +184,7 @@ shared_ptr<DownstreamState> chashedFromHash(const ServerPolicy::NumberedServerVe
     }
 
     if (totalWeight > 0) {
-      targetLoad = (currentLoad / totalWeight) * consistentHashBalancingFactor;
+      targetLoad = (currentLoad / static_cast<double>(totalWeight)) * consistentHashBalancingFactor;
     }
   }
 
index 214b1564221e5e8dab7e3f66898d3d715ca8f3d0..c59182750dc5d752c32f7889b9bdefdbd99a9b2b 100644 (file)
@@ -1163,12 +1163,12 @@ size_t dnsdist_ffi_packetcache_get_domain_list_by_addr(const char* poolName, con
   }
 
   const auto& pools = dnsdist::configuration::getCurrentRuntimeConfiguration().d_pools;
-  auto it = pools.find(poolName);
-  if (it == pools.end()) {
+  auto poolIt = pools.find(poolName);
+  if (poolIt == pools.end()) {
     return 0;
   }
 
-  auto pool = it->second;
+  auto pool = poolIt->second;
   if (!pool->packetCache) {
     return 0;
   }
@@ -1212,12 +1212,12 @@ size_t dnsdist_ffi_packetcache_get_address_list_by_domain(const char* poolName,
   }
 
   const auto& pools = dnsdist::configuration::getCurrentRuntimeConfiguration().d_pools;
-  auto it = pools.find(poolName);
-  if (it == pools.end()) {
+  auto poolIt = pools.find(poolName);
+  if (poolIt == pools.end()) {
     return 0;
   }
 
-  auto pool = it->second;
+  auto pool = poolIt->second;
   if (!pool->packetCache) {
     return 0;
   }
index 3051da855194806596cad5ac58ae86410a86f0f9..647f6248733fa3692bdc5450ed1724af59a6ba93 100644 (file)
@@ -720,7 +720,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
                          }
                          else if (auto* str = boost::get<std::string>(&var)) {
                            const auto uuid = getUniqueID(*str);
-                           for (auto& state : dnsdist::configuration::getCurrentRuntimeConfiguration().d_backends) {
+                           for (const auto& state : dnsdist::configuration::getCurrentRuntimeConfiguration().d_backends) {
                              if (*state->d_config.id == uuid) {
                                server = state;
                              }
index 593f1045c5e4c24526a4a967b673d6a45b05f7c9..be07bd9fe8232cdbf45573bc29195f79f5c4a47f 100644 (file)
@@ -282,7 +282,7 @@ static netsnmp_variable_list* backendStatTable_get_first_data_point(void** loop_
   auto backends = dnsdist::configuration::getCurrentRuntimeConfiguration().d_backends;
   s_servers.clear();
   s_servers.reserve(backends.size());
-  for (const auto& server : backends) {
+  for (auto& server : backends) {
     s_servers.push_back(std::move(server));
   }
 
index 7b81baeee00e3910d9c935b183ee3e8328878513..6e92f458061199ab70c8818c462ad5a23b349a1e 100644 (file)
@@ -2486,7 +2486,7 @@ static void setupLocalSocket(ClientState& clientState, const ComboAddress& addr,
       SSetsockopt(socket, IPPROTO_TCP, TCP_FASTOPEN, clientState.fastOpenQueueSize);
 #ifdef TCP_FASTOPEN_KEY
       if (!immutableConfig.d_tcpFastOpenKey.empty()) {
-        auto res = setsockopt(socket, IPPROTO_IP, TCP_FASTOPEN_KEY, immutableConfig.d_tcpFastOpenKey.data(), immutableConfig.d_tcpFastOpenKey.size() * sizeof(immutableConfig.d_tcpFastOpenKey.at(0)));
+        auto res = setsockopt(socket, IPPROTO_IP, TCP_FASTOPEN_KEY, immutableConfig.d_tcpFastOpenKey.data(), immutableConfig.d_tcpFastOpenKey.size() * sizeof(immutableConfig.d_tcpFastOpenKey[0]));
         if (res == -1) {
           throw runtime_error("setsockopt for level IPPROTO_TCP and opname TCP_FASTOPEN_KEY failed: " + stringerror());
         }
index 0db9579a5bcb6f7fa45ae59b8532836300afd5e1..388389f66fba9c649e070e3fe9ef08ee1a6a7735 100644 (file)
@@ -376,7 +376,7 @@ BOOST_FIXTURE_TEST_CASE(test_DynBlockRulesGroup_QueryRate_V4Ports, TestFixture)
     /* we (again) insert just above 50 qps from several clients the same IPv4 port range, this should update the block which will
        check by looking at the blocked counter */
     {
-      auto block = dnsdist::DynamicBlocks::getClientAddressDynamicRules().lookup(AddressAndPortRange(ComboAddress("192.0.2.1:0"), 32, 16));
+      auto* block = dnsdist::DynamicBlocks::getClientAddressDynamicRules().lookup(AddressAndPortRange(ComboAddress("192.0.2.1:0"), 32, 16));
       BOOST_REQUIRE(block != nullptr);
       BOOST_CHECK_EQUAL(block->second.blocks, 0U);
       block->second.blocks = 42U;
@@ -397,7 +397,7 @@ BOOST_FIXTURE_TEST_CASE(test_DynBlockRulesGroup_QueryRate_V4Ports, TestFixture)
     BOOST_CHECK_EQUAL(dnsdist::DynamicBlocks::getClientAddressDynamicRules().size(), 1U);
     {
       /* previous address/port should still be blocked */
-      auto block = dnsdist::DynamicBlocks::getClientAddressDynamicRules().lookup(AddressAndPortRange(ComboAddress("192.0.2.1:0"), 32, 16));
+      auto* block = dnsdist::DynamicBlocks::getClientAddressDynamicRules().lookup(AddressAndPortRange(ComboAddress("192.0.2.1:0"), 32, 16));
       BOOST_REQUIRE(block != nullptr);
       BOOST_CHECK_EQUAL(block->second.blocks, 42U);
     }
index 1eb819e49131099342de236845972a976d2e714e..e641dc63715475c6ae7d3d4fe34a17ce2a7da73a 100644 (file)
@@ -560,7 +560,7 @@ BOOST_AUTO_TEST_CASE(test_lua)
   )foo";
   resetLuaContext();
   g_lua.lock()->writeFunction("setServerPolicyLua", [](const string& name, const ServerPolicy::policyfunc_t& policy) {
-    auto pol = std::make_shared<ServerPolicy>(name, std::move(policy), true);
+    auto pol = std::make_shared<ServerPolicy>(name, policy, true);
     dnsdist::configuration::updateRuntimeConfiguration([&pol](dnsdist::configuration::RuntimeConfiguration& config) {
       config.d_lbPolicy = std::move(pol);
     });