]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Fix auto_causes_copy coverity reports. 12039/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 28 Sep 2022 10:10:29 +0000 (12:10 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 28 Sep 2022 10:15:51 +0000 (12:15 +0200)
In once case we actually want a copy so annotate it.

Coverity 380098, 380102, 380103, 380106, 380107, 280109, 380111, 380112, 380113, 380117

pdns/dnscrypt.cc
pdns/dnsdist-lua-inspection.cc
pdns/dnsdist-web.cc
pdns/dnsdist.cc
pdns/dnsdistdist/dnsdist-lua-bindings-dnscrypt.cc
pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc

index 539789fdff6e98b7853e85a3af50b99869d21137..6db8613a3d01899c1d3844d6d647bfe44f8055f5 100644 (file)
@@ -289,7 +289,7 @@ void DNSCryptContext::addNewCertificate(std::shared_ptr<DNSCryptCertificatePair>
 {
   auto certs = d_certs.write_lock();
 
-  for (auto pair : *certs) {
+  for (const auto& pair : *certs) {
     if (pair->cert.getSerial() == newCert->cert.getSerial()) {
       if (reload) {
         /* on reload we just assume that this is the same certificate */
@@ -356,7 +356,7 @@ std::vector<std::shared_ptr<DNSCryptCertificatePair>> DNSCryptContext::getCertif
 
 void DNSCryptContext::markActive(uint32_t serial)
 {
-  for (auto pair : *d_certs.write_lock()) {
+  for (const auto& pair : *d_certs.write_lock()) {
     if (pair->active == false && pair->cert.getSerial() == serial) {
       pair->active = true;
       return;
@@ -367,7 +367,7 @@ void DNSCryptContext::markActive(uint32_t serial)
 
 void DNSCryptContext::markInactive(uint32_t serial)
 {
-  for (auto pair : *d_certs.write_lock()) {
+  for (const auto& pair : *d_certs.write_lock()) {
     if (pair->active == true && pair->cert.getSerial() == serial) {
       pair->active = false;
       return;
index 6e02284c74024e6c0d688a971c7856c48b36964c..6f59a6c423324dbbd6cb231fa00143034222572f 100644 (file)
@@ -298,7 +298,8 @@ void setupLuaInspection(LuaContext& luaCtx)
        unsigned int lab = *labels;
         for (const auto& shard : g_rings.d_shards) {
           auto rl = shard->queryRing.lock();
-          for(auto a : *rl) {
+          // coverity[auto_causes_copy]
+          for (auto a : *rl) {
             a.name.trimToLabels(lab);
             counts[a.name]++;
             total++;
index 7aba31a28bad7ddf10191936ec756db59877b026..603a8e5bee0432fa1f9939dc2a0ef502d69df995 100644 (file)
@@ -1412,7 +1412,7 @@ static void handleAllowFrom(const YaHTTP::Request& req, YaHTTP::Response& resp)
       auto aclList = doc["value"];
       if (aclList.is_array()) {
 
-        for (auto value : aclList.array_items()) {
+        for (const auto& value : aclList.array_items()) {
           try {
             nmg.addMask(value.string_value());
           } catch (NetmaskException &e) {
index 7cc858474d8663bf1bce6dd9cb0d8592390354e6..353f19feb58b6ad85b9e5f695acb250cd2283464 100644 (file)
@@ -1865,7 +1865,7 @@ static void maintThread()
       }
 
       const time_t now = time(nullptr);
-      for (auto pair : caches) {
+      for (const auto& pair : caches) {
         /* shall we keep expired entries ? */
         if (pair.second == true) {
           continue;
index fd3fb39e53f56bc6ef11a8b0b3dcfb44d87deedf..50e34f252704f539446a53a50e60d98298dbc8a0 100644 (file)
@@ -56,7 +56,7 @@ void setupLuaBindingsDNSCrypt(LuaContext& luaCtx, bool client)
 
       if (ctx != nullptr) {
         size_t idx = 1;
-        for (auto pair : ctx->getCertificates()) {
+        for (const auto& pair : ctx->getCertificates()) {
           result.push_back({idx++, pair});
         }
       }
@@ -101,7 +101,7 @@ void setupLuaBindingsDNSCrypt(LuaContext& luaCtx, bool client)
         boost::format fmt("%1$-3d %|5t|%2$-8d %|10t|%3$-7d %|20t|%4$-21.21s %|41t|%5$-21.21s");
         ret << (fmt % "#" % "Serial" % "Version" % "From" % "To" ) << endl;
 
-        for (auto pair : ctx->getCertificates()) {
+        for (const auto& pair : ctx->getCertificates()) {
           const auto cert = pair->cert;
           const DNSCryptExchangeVersion version = DNSCryptContext::getExchangeVersion(cert);
 
index 120edf30e55eeea92feab3642f9196c31328cf23..0873ff648a1a8c3d4c1611c02b1b2c882442c02c 100644 (file)
@@ -95,7 +95,7 @@ void setupLuaBindingsPacketCache(LuaContext& luaCtx, bool client)
           }
         }
         if (vars->count("skipOptions")) {
-          for (auto option: boost::get<LuaArray<uint16_t>>(vars->at("skipOptions"))) {
+          for (const auto& option: boost::get<LuaArray<uint16_t>>(vars->at("skipOptions"))) {
             optionsToSkip.insert(option.second);
           }
         }