]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Fix static analysis warnings (again)
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 24 Jun 2024 11:32:25 +0000 (13:32 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 15 Jul 2024 09:48:00 +0000 (11:48 +0200)
pdns/dnsdistdist/dnsdist-dynblocks.cc
pdns/dnsdistdist/dnsdist-lbpolicies.cc
pdns/dnsdistdist/dnsdist-lbpolicies.hh
pdns/dnsdistdist/dnsdist.cc
pdns/dnsdistdist/test-dnsdisttcp_cc.cc

index 371a0f1194ff08a991b1e8ef5b7407a71c6ed41a..ee0367a06c92c2f68a042460273c6df9087383be 100644 (file)
@@ -773,7 +773,7 @@ void DynBlockMaintenance::run()
   time_t now = time(nullptr);
   auto purgeInterval = dnsdist::configuration::getCurrentRuntimeConfiguration().d_dynBlocksPurgeInterval;
   time_t nextExpiredPurge = now + purgeInterval;
-  time_t nextMetricsCollect = now + metricsCollectionInterval;
+  time_t nextMetricsCollect = now + static_cast<time_t>(metricsCollectionInterval);
   time_t nextMetricsGeneration = now + metricsGenerationInterval;
 
   while (true) {
@@ -813,7 +813,7 @@ void DynBlockMaintenance::run()
         purgeExpired(tspec);
 
         now = time(nullptr);
-        nextExpiredPurge = now + purgeInterval;
+        nextExpiredPurge = now + static_cast<time_t>(purgeInterval);
       }
     }
     catch (const std::exception& e) {
index a648435a0a0d6d38443a4bbec4830dba10bd7a3e..6fb2c24b434338b18b29188bce217b1a242c1888 100644 (file)
@@ -256,7 +256,7 @@ shared_ptr<DownstreamState> roundrobin(const ServerPolicy::NumberedServerVector&
   return servers.at(candidates.at((counter++) % candidates.size()) - 1).second;
 }
 
-const std::shared_ptr<const ServerPolicy::NumberedServerVector> getDownstreamCandidates(const std::string& poolName)
+std::shared_ptr<const ServerPolicy::NumberedServerVector> getDownstreamCandidates(const std::string& poolName)
 {
   std::shared_ptr<ServerPool> pool = getPool(poolName);
   return pool->getServers();
@@ -266,9 +266,9 @@ std::shared_ptr<ServerPool> createPoolIfNotExists(const string& poolName)
 {
   {
     const auto& pools = dnsdist::configuration::getCurrentRuntimeConfiguration().d_pools;
-    const auto it = pools.find(poolName);
-    if (it != pools.end()) {
-      return it->second;
+    const auto poolIt = pools.find(poolName);
+    if (poolIt != pools.end()) {
+      return poolIt->second;
     }
   }
 
@@ -323,12 +323,12 @@ void removeServerFromPool(const string& poolName, std::shared_ptr<DownstreamStat
 std::shared_ptr<ServerPool> getPool(const std::string& 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()) {
     throw std::out_of_range("No pool named " + poolName);
   }
 
-  return it->second;
+  return poolIt->second;
 }
 
 ServerPolicy::ServerPolicy(const std::string& name_, const std::string& code): d_name(name_), d_perThreadPolicyCode(code), d_isLua(true), d_isFFI(true), d_isPerThread(true)
index b92237861d4a91600982c6d75db4c2b2c241ff5d..ce95addab9c58062d20b6a0d71487f9efdf684a9 100644 (file)
@@ -100,7 +100,7 @@ void setPoolPolicy(const string& poolName, std::shared_ptr<ServerPolicy> policy)
 void addServerToPool(const string& poolName, std::shared_ptr<DownstreamState> server);
 void removeServerFromPool(const string& poolName, std::shared_ptr<DownstreamState> server);
 
-const std::shared_ptr<const ServerPolicy::NumberedServerVector> getDownstreamCandidates(const std::string& poolName);
+std::shared_ptr<const ServerPolicy::NumberedServerVector> getDownstreamCandidates(const std::string& poolName);
 
 std::shared_ptr<DownstreamState> firstAvailable(const ServerPolicy::NumberedServerVector& servers, const DNSQuestion* dq);
 
index 6e92f458061199ab70c8818c462ad5a23b349a1e..50d1de1851f9063ec5808a74363ca227d4c0a37c 100644 (file)
@@ -3457,7 +3457,7 @@ int main(int argc, char** argv)
     /* create the default pool no matter what */
     createPoolIfNotExists("");
 
-    for (auto& backend : dnsdist::configuration::getCurrentRuntimeConfiguration().d_backends) {
+    for (const auto& backend : dnsdist::configuration::getCurrentRuntimeConfiguration().d_backends) {
       if (backend->connected) {
         backend->start();
       }
index 8fa4a636bf45876a17e27639b376812388ed1898..bcf6ea10aa21a7839b4a9f286f5fd1b8701f6805 100644 (file)
@@ -57,10 +57,10 @@ void handleResponseSent(const InternalQueryState& ids, double udiff, const Combo
 
 std::function<ProcessQueryResult(DNSQuestion& dq, std::shared_ptr<DownstreamState>& selectedBackend)> s_processQuery;
 
-ProcessQueryResult processQuery(DNSQuestion& dq, std::shared_ptr<DownstreamState>& selectedBackend)
+ProcessQueryResult processQuery(DNSQuestion& dnsQuestion, std::shared_ptr<DownstreamState>& selectedBackend)
 {
   if (s_processQuery) {
-    return s_processQuery(dq, selectedBackend);
+    return s_processQuery(dnsQuestion, selectedBackend);
   }
 
   return ProcessQueryResult::Drop;
@@ -1767,6 +1767,7 @@ BOOST_FIXTURE_TEST_CASE(test_IncomingConnection_BackendNoOOOR, TestFixture)
   }
 }
 
+// NOLINTNEXTLINE(readability-function-cognitive-complexity)
 BOOST_FIXTURE_TEST_CASE(test_IncomingConnectionOOOR_BackendOOOR, TestFixture)
 {
   const auto tcpRecvTimeout = dnsdist::configuration::getCurrentRuntimeConfiguration().d_tcpRecvTimeout;