From: Miod Vallat Date: Fri, 25 Apr 2025 07:39:38 +0000 (+0200) Subject: Various move vs copy improvements pointed by Coverity. X-Git-Tag: dnsdist-2.0.0-alpha2~38^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5db294ba0cd782f2b42e840e35ebd15b600f262c;p=thirdparty%2Fpdns.git Various move vs copy improvements pointed by Coverity. --- diff --git a/modules/bindbackend/bindbackend2.cc b/modules/bindbackend/bindbackend2.cc index 359aa50224..9b0f1fc075 100644 --- a/modules/bindbackend/bindbackend2.cc +++ b/modules/bindbackend/bindbackend2.cc @@ -540,8 +540,7 @@ void Bind2Backend::insertRecord(std::shared_ptr& records, const g_log << Logger::Warning << msg << " ignored" << endl; return; } - else - throw PDNSException(msg); + throw PDNSException(std::move(msg)); } // bdr.qname.swap(bdr.qname); diff --git a/modules/geoipbackend/geoipbackend.cc b/modules/geoipbackend/geoipbackend.cc index adcf60f1e6..a7360b1b26 100644 --- a/modules/geoipbackend/geoipbackend.cc +++ b/modules/geoipbackend/geoipbackend.cc @@ -1009,7 +1009,7 @@ bool GeoIPBackend::getDomainKeys(const ZoneName& name, std::vector& keys for (auto id : ids) { if (txn.get(id, key)) { KeyData kd{key.content, id, key.flags, key.active, key.published}; - keys.push_back(kd); + keys.emplace_back(std::move(kd)); } } diff --git a/modules/lua2backend/lua2api2.hh b/modules/lua2backend/lua2api2.hh index 03289ef046..05882eaee8 100644 --- a/modules/lua2backend/lua2api2.hh +++ b/modules/lua2backend/lua2api2.hh @@ -387,7 +387,7 @@ public: g_log << Logger::Warning << "[" << getPrefix() << "] Unsupported key '" << item.first << "' in keydata result" << endl; } logResult("id=" << key.id << ",flags=" << key.flags << ",active=" << (key.active ? "true" : "false") << ",published=" << (key.published ? "true" : "false")); - keys.push_back(key); + keys.emplace_back(std::move(key)); } return true; diff --git a/modules/remotebackend/remotebackend.cc b/modules/remotebackend/remotebackend.cc index 8e05d651c8..53804e34ab 100644 --- a/modules/remotebackend/remotebackend.cc +++ b/modules/remotebackend/remotebackend.cc @@ -432,7 +432,7 @@ bool RemoteBackend::getDomainKeys(const ZoneName& name, std::vectord_st.serial; } - replacement.push_back(rr); + replacement.emplace_back(std::move(rr)); } di.backend->replaceRRSet(di.id, g.first.first.operator const DNSName&() + domain.operator const DNSName&(), QType(g.first.second), replacement); @@ -772,7 +772,7 @@ void CommunicatorClass::suck(const ZoneName& domain, const ComboAddress& remote, auto sd = getRR(dr); zs.soa_serial = sd->d_st.serial; } - rrs.push_back(rr); + rrs.emplace_back(std::move(rr)); } } else { diff --git a/pdns/communicator.hh b/pdns/communicator.hh index 2ff0e2d56c..e95181c118 100644 --- a/pdns/communicator.hh +++ b/pdns/communicator.hh @@ -91,7 +91,7 @@ public: nr.id = dns_random_uint16(); nr.next = time(nullptr) + delay; - d_nqueue.push_back(nr); + d_nqueue.push_back(std::move(nr)); } bool removeIf(const ComboAddress& remote, uint16_t id, const ZoneName& domain) diff --git a/pdns/dbdnsseckeeper.cc b/pdns/dbdnsseckeeper.cc index c8ec62d910..908fe8e091 100644 --- a/pdns/dbdnsseckeeper.cc +++ b/pdns/dbdnsseckeeper.cc @@ -394,7 +394,7 @@ bool DNSSECKeeper::setNSEC3PARAM(const ZoneName& zname, const NSEC3PARAMRecordCo string descr = ns3p.getZoneRepresentation(); vector meta; - meta.push_back(descr); + meta.emplace_back(std::move(descr)); if (d_keymetadb->setDomainMetadata(zname, "NSEC3PARAM", meta)) { meta.clear(); diff --git a/pdns/dnssecsigner.cc b/pdns/dnssecsigner.cc index 4b5032561b..a708dd9035 100644 --- a/pdns/dnssecsigner.cc +++ b/pdns/dnssecsigner.cc @@ -196,7 +196,7 @@ static bool getBestAuthFromSet(const set& authSet, const DNSName& name ZoneName sname(name); do { if(authSet.find(sname) != authSet.end()) { - signer = sname; + signer = std::move(sname); return true; } } diff --git a/pdns/tcpreceiver.cc b/pdns/tcpreceiver.cc index b5d22eea86..d5615e2c10 100644 --- a/pdns/tcpreceiver.cc +++ b/pdns/tcpreceiver.cc @@ -1011,7 +1011,8 @@ send: typedef map nsecxrepo_t; nsecxrepo_t nsecxrepo; - ChunkedSigningPipe csp(targetZone, (securedZone && !presignedZone), ::arg().asNum("signing-threads", 1), ::arg().mustDo("workaround-11804") ? 1 : 100); + // std::move(targetZone) below is ok as it is no longer used afterwards + ChunkedSigningPipe csp(std::move(targetZone), (securedZone && !presignedZone), ::arg().asNum("signing-threads", 1), ::arg().mustDo("workaround-11804") ? 1 : 100); DNSName keyname; unsigned int udiff;