From: Remi Gacogne Date: Mon, 24 Jun 2024 07:44:42 +0000 (+0200) Subject: dnsdist: Fix static analysis warnings X-Git-Tag: rec-5.2.0-alpha1~172^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=838e0273376d22bd9ff3607c2748b4e2ca9f6aa7;p=thirdparty%2Fpdns.git dnsdist: Fix static analysis warnings --- diff --git a/pdns/dnsdistdist/dnsdist-carbon.cc b/pdns/dnsdistdist/dnsdist-carbon.cc index 5df2049352..ee396d0452 100644 --- a/pdns/dnsdistdist/dnsdist-carbon.cc +++ b/pdns/dnsdistdist/dnsdist-carbon.cc @@ -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& endpoints) { - for (auto& endpoint : endpoints) { + for (const auto& endpoint : endpoints) { std::thread newHandler(carbonHandler, endpoint); newHandler.detach(); } diff --git a/pdns/dnsdistdist/dnsdist-lbpolicies.cc b/pdns/dnsdistdist/dnsdist-lbpolicies.cc index 31d772ddb2..a648435a0a 100644 --- a/pdns/dnsdistdist/dnsdist-lbpolicies.cc +++ b/pdns/dnsdistdist/dnsdist-lbpolicies.cc @@ -184,7 +184,7 @@ shared_ptr chashedFromHash(const ServerPolicy::NumberedServerVe } if (totalWeight > 0) { - targetLoad = (currentLoad / totalWeight) * consistentHashBalancingFactor; + targetLoad = (currentLoad / static_cast(totalWeight)) * consistentHashBalancingFactor; } } diff --git a/pdns/dnsdistdist/dnsdist-lua-ffi.cc b/pdns/dnsdistdist/dnsdist-lua-ffi.cc index 214b156422..c59182750d 100644 --- a/pdns/dnsdistdist/dnsdist-lua-ffi.cc +++ b/pdns/dnsdistdist/dnsdist-lua-ffi.cc @@ -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; } diff --git a/pdns/dnsdistdist/dnsdist-lua.cc b/pdns/dnsdistdist/dnsdist-lua.cc index 3051da8551..647f624873 100644 --- a/pdns/dnsdistdist/dnsdist-lua.cc +++ b/pdns/dnsdistdist/dnsdist-lua.cc @@ -720,7 +720,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) } else if (auto* str = boost::get(&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; } diff --git a/pdns/dnsdistdist/dnsdist-snmp.cc b/pdns/dnsdistdist/dnsdist-snmp.cc index 593f1045c5..be07bd9fe8 100644 --- a/pdns/dnsdistdist/dnsdist-snmp.cc +++ b/pdns/dnsdistdist/dnsdist-snmp.cc @@ -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)); } diff --git a/pdns/dnsdistdist/dnsdist.cc b/pdns/dnsdistdist/dnsdist.cc index 7b81baeee0..6e92f45806 100644 --- a/pdns/dnsdistdist/dnsdist.cc +++ b/pdns/dnsdistdist/dnsdist.cc @@ -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()); } diff --git a/pdns/dnsdistdist/test-dnsdistdynblocks_hh.cc b/pdns/dnsdistdist/test-dnsdistdynblocks_hh.cc index 0db9579a5b..388389f66f 100644 --- a/pdns/dnsdistdist/test-dnsdistdynblocks_hh.cc +++ b/pdns/dnsdistdist/test-dnsdistdynblocks_hh.cc @@ -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); } diff --git a/pdns/dnsdistdist/test-dnsdistlbpolicies_cc.cc b/pdns/dnsdistdist/test-dnsdistlbpolicies_cc.cc index 1eb819e491..e641dc6371 100644 --- a/pdns/dnsdistdist/test-dnsdistlbpolicies_cc.cc +++ b/pdns/dnsdistdist/test-dnsdistlbpolicies_cc.cc @@ -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(name, std::move(policy), true); + auto pol = std::make_shared(name, policy, true); dnsdist::configuration::updateRuntimeConfiguration([&pol](dnsdist::configuration::RuntimeConfiguration& config) { config.d_lbPolicy = std::move(pol); });