Skip to content

Commit

Permalink
Merge pull request #15050 from omoerbeek/rec-coverity-20240117
Browse files Browse the repository at this point in the history
rec: New Coverity Variable copied when it could be moved cases
  • Loading branch information
omoerbeek authored Jan 17, 2025
2 parents 903549d + 8845064 commit a3a1901
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pdns/arguments.cc
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ void ArgvMap::parseOne(const string& arg, const string& parseOnly, bool lax)
}
else {
d_params[var] = val;
d_cleared.insert(var);
d_cleared.insert(std::move(var));
}
}
else {
Expand Down
4 changes: 2 additions & 2 deletions pdns/dnsparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ void PacketReader::xfrSvcParamKeyVals(set<SvcParam> &kvs) {
throw std::out_of_range("alpn length of 0");
}
xfrBlob(alpn, alpnLen);
alpns.push_back(alpn);
alpns.push_back(std::move(alpn));
}
kvs.insert(SvcParam(key, std::move(alpns)));
break;
Expand Down Expand Up @@ -672,7 +672,7 @@ void PacketReader::xfrSvcParamKeyVals(set<SvcParam> &kvs) {
bool doAuto{d_internal && len == 0};
auto param = SvcParam(key, std::move(addresses));
param.setAutoHint(doAuto);
kvs.insert(param);
kvs.insert(std::move(param));
break;
}
case SvcParam::ech: {
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnsrecords.cc
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ void SVCBBaseRecordContent::setHints(const SvcParam::SvcParamKey &key, const std
try {
auto newParam = SvcParam(key, std::move(h));
d_params.erase(p);
d_params.insert(newParam);
d_params.insert(std::move(newParam));
} catch (...) {
// XXX maybe we should SERVFAIL instead?
return;
Expand Down
4 changes: 2 additions & 2 deletions pdns/rcpgenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ void RecordTextReader::xfrSvcParamKeyVals(set<SvcParam>& val) // NOLINT(readabil
try {
auto p = SvcParam(key, std::move(hints));
p.setAutoHint(doAuto);
val.insert(p);
val.insert(std::move(p));
}
catch (const std::invalid_argument& e) {
throw RecordTextException(e.what());
Expand Down Expand Up @@ -880,7 +880,7 @@ void RecordTextWriter::xfrSVCBValueList(const vector<string> &val) {
}
unescaped += ch;
}
escaped.push_back(unescaped);
escaped.push_back(std::move(unescaped));
}
if (shouldQuote) {
d_string.append(1, '"');
Expand Down
2 changes: 1 addition & 1 deletion pdns/recursordist/lua-recursor4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void RecursorLua4::DNSQuestion::addRecord(uint16_t type, const std::string& cont
dnsRecord.d_type = type;
dnsRecord.d_place = place;
dnsRecord.setContent(DNSRecordContent::make(type, QClass::IN, content));
records.push_back(dnsRecord);
records.push_back(std::move(dnsRecord));
}

void RecursorLua4::DNSQuestion::addAnswer(uint16_t type, const std::string& content, boost::optional<int> ttl, boost::optional<string> name)
Expand Down
2 changes: 1 addition & 1 deletion pdns/recursordist/pdns_recursor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ int getFakePTRRecords(const DNSName& qname, vector<DNSRecord>& ret)
record.setContent(std::make_shared<CNAMERecordContent>(newquery));
// Copy the TTL of the synthesized CNAME from the actual answer
record.d_ttl = (rcode == RCode::NoError && !answers.empty()) ? answers.at(0).d_ttl : SyncRes::s_minimumTTL;
ret.push_back(record);
ret.push_back(std::move(record));

ret.insert(ret.end(), answers.begin(), answers.end());

Expand Down
2 changes: 1 addition & 1 deletion pdns/recursordist/pubsuffixloader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void initPublicSuffixList(const std::string& file)
vector<string> parts;
stringtok(parts, low, ".");
reverse(parts.begin(), parts.end());
pbList.push_back(parts);
pbList.push_back(std::move(parts));
}
}

Expand Down
2 changes: 1 addition & 1 deletion pdns/recursordist/rec-lua-conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ void loadRecursorLuaConfig(const std::string& fname, ProxyMapping& proxyMapping,

try {
Lua->executeCode(ifs);
newLuaConfig = lci;
newLuaConfig = std::move(lci);
}
catch (const LuaContext::ExecutionErrorException& e) {
SLOG(g_log << Logger::Error << "Unable to load Lua script from '" + fname + "': ",
Expand Down
4 changes: 2 additions & 2 deletions pdns/recursordist/rec-zonetocache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void ZoneData::parseDRForCache(DNSRecord& dnsRecord)
case QType::NSEC3:
break;
case QType::RRSIG: {
const auto rrsig = getRR<RRSIGRecordContent>(dnsRecord);
auto rrsig = getRR<RRSIGRecordContent>(dnsRecord);
if (rrsig == nullptr) {
break;
}
Expand All @@ -110,7 +110,7 @@ void ZoneData::parseDRForCache(DNSRecord& dnsRecord)
}
else {
vector<shared_ptr<const RRSIGRecordContent>> sigsrr;
sigsrr.push_back(rrsig);
sigsrr.push_back(std::move(rrsig));
d_sigs.insert({sigkey, sigsrr});
}
break;
Expand Down
6 changes: 3 additions & 3 deletions pdns/recursordist/rec_channel_rec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,7 @@ DNSName getRegisteredName(const DNSName& dom)
while (!parts.empty()) {
if (parts.size() == 1 || binary_search(g_pubs.begin(), g_pubs.end(), parts)) {

string ret = last;
string ret = std::move(last);
if (!ret.empty())
ret += ".";

Expand Down Expand Up @@ -1643,7 +1643,7 @@ static string addDontThrottleNames(T begin, T end)
while (begin != end) {
try {
auto d = DNSName(*begin);
toAdd.push_back(d);
toAdd.push_back(std::move(d));
}
catch (const std::exception& e) {
return "Problem parsing '" + *begin + "': " + e.what() + ", nothing added\n";
Expand Down Expand Up @@ -1936,7 +1936,7 @@ RecursorControlChannel::Answer luaconfig(bool broadcast)
lci = g_luaconfs.getCopy();
if (broadcast) {
startLuaConfigDelayedThreads(lci, lci.generation);
broadcastFunction([=] { return pleaseSupplantProxyMapping(proxyMapping); });
broadcastFunction([pmap = std::move(proxyMapping)] { return pleaseSupplantProxyMapping(pmap); });
}
else {
// Initial proxy mapping
Expand Down
4 changes: 2 additions & 2 deletions pdns/recursordist/reczones.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ string reloadZoneConfiguration(bool yaml)
// these explicitly-named captures should not be necessary, as lambda
// capture of tuple-like structured bindings is permitted, but some
// compilers still don't allow it
broadcastFunction([dmap = newDomainMap] { return pleaseUseNewSDomainsMap(dmap); });
broadcastFunction([nsset = newNotifySet] { return pleaseSupplantAllowNotifyFor(nsset); });
broadcastFunction([dmap = std::move(newDomainMap)] { return pleaseUseNewSDomainsMap(dmap); });
broadcastFunction([nsset = std::move(newNotifySet)] { return pleaseSupplantAllowNotifyFor(nsset); });

// Wipe the caches *after* the new auth domain info has been set
// up, as a query during setting up might fill the caches
Expand Down
2 changes: 1 addition & 1 deletion pdns/recursordist/settings/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def gen_cxx_oldkvtobridgestruct(file, entries):
file.write('const std::string& value, ::rust::String& section, ::rust::String& fieldname, ')
file.write('::rust::String& type_name, pdns::rust::settings::rec::Value& rustvalue)')
file.write('{ // NOLINT(readability-function-cognitive-complexity)\n')
file.write(' if (const auto newname = arg().isDeprecated(key); !newname.empty()) {\n')
file.write(' if (const auto& newname = arg().isDeprecated(key); !newname.empty()) {\n')
file.write(' key = newname;\n')
file.write(' }\n')
for entry in entries:
Expand Down
18 changes: 9 additions & 9 deletions pdns/recursordist/syncres.cc
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ void SyncRes::AuthDomain::addSOA(std::vector<DNSRecord>& records) const
if (ziter != d_records.end()) {
DNSRecord dnsRecord = *ziter;
dnsRecord.d_place = DNSResourceRecord::AUTHORITY;
records.push_back(dnsRecord);
records.push_back(std::move(dnsRecord));
}
}

Expand Down Expand Up @@ -1028,7 +1028,7 @@ int SyncRes::AuthDomain::getRecords(const DNSName& qname, const QType qtype, std
if (dnsRecord.d_type == qtype || qtype == QType::ANY || dnsRecord.d_type == QType::CNAME) {
dnsRecord.d_name = qname;
dnsRecord.d_place = DNSResourceRecord::ANSWER;
records.push_back(dnsRecord);
records.push_back(std::move(dnsRecord));
}
}

Expand Down Expand Up @@ -2592,7 +2592,7 @@ bool SyncRes::doCNAMECacheCheck(const DNSName& qname, const QType qtype, vector<
break;
}
if (g_recCache->get(d_now.tv_sec, dnameName, QType::DNAME, flags, &cset, d_cacheRemote, d_routingTag, d_doDNSSEC ? &signatures : nullptr, d_doDNSSEC ? &authorityRecs : nullptr, &d_wasVariable, &context.state, &wasAuth, &authZone, &d_fromAuthIP) > 0) {
foundName = dnameName;
foundName = std::move(dnameName);
foundQT = QType::DNAME;
break;
}
Expand Down Expand Up @@ -2664,13 +2664,13 @@ bool SyncRes::doCNAMECacheCheck(const DNSName& qname, const QType qtype, vector<
sigdr.setContent(signature);
sigdr.d_place = DNSResourceRecord::ANSWER;
sigdr.d_class = QClass::IN;
ret.push_back(sigdr);
ret.push_back(std::move(sigdr));
}

for (const auto& rec : *authorityRecs) {
DNSRecord authDR(rec);
authDR.d_ttl = ttl;
ret.push_back(authDR);
ret.push_back(std::move(authDR));
}
}

Expand Down Expand Up @@ -3099,7 +3099,7 @@ bool SyncRes::doCacheCheck(const DNSName& qname, const DNSName& authname, bool w
dnsRecord.setContent(signature);
dnsRecord.d_place = DNSResourceRecord::ANSWER;
dnsRecord.d_class = QClass::IN;
ret.push_back(dnsRecord);
ret.push_back(std::move(dnsRecord));
}

for (const auto& rec : *authorityRecs) {
Expand Down Expand Up @@ -4025,7 +4025,7 @@ vState SyncRes::getDNSKeys(const DNSName& signer, skeyset_t& keys, bool& servFai
if (key.d_type == QType::DNSKEY) {
auto content = getRR<DNSKEYRecordContent>(key);
if (content) {
keys.insert(content);
keys.insert(std::move(content));
}
}
}
Expand Down Expand Up @@ -4246,7 +4246,7 @@ static void allowAdditionalEntry(std::unordered_set<DNSName>& allowedAdditionals
if (target.isRoot()) {
target = rec.d_name;
}
allowedAdditionals.insert(target);
allowedAdditionals.insert(std::move(target));
}
else {
// FIXME: Alias mode not implemented yet
Expand Down Expand Up @@ -4710,7 +4710,7 @@ RCode::rcodes_ SyncRes::updateCacheFromRecords(unsigned int depth, const string&
tcache[{rec.d_name, rec.d_type, rec.d_place}].d_ttl_time = d_now.tv_sec;
dnsRecord.d_ttl += d_now.tv_sec;
dnsRecord.d_place = DNSResourceRecord::ANSWER;
tcache[{rec.d_name, rec.d_type, rec.d_place}].records.push_back(dnsRecord);
tcache[{rec.d_name, rec.d_type, rec.d_place}].records.push_back(std::move(dnsRecord));
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion pdns/recursordist/validate-recursor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool updateTrustAnchorsFromFile(const std::string& fname, map<DNSName, dsset_t>&
throw PDNSException("Unable to parse DNSKEY record '" + resourceRecord.qname.toString() + " " + resourceRecord.getZoneRepresentation() + "'");
}
auto dsr = makeDSFromDNSKey(resourceRecord.qname, *dnskeyr, DNSSECKeeper::DIGEST_SHA256);
newDSAnchors[resourceRecord.qname].insert(dsr);
newDSAnchors[resourceRecord.qname].insert(std::move(dsr));
}
}
if (dsAnchors == newDSAnchors) {
Expand Down

0 comments on commit a3a1901

Please sign in to comment.