From 17417d541991bb4459f99f5d0dfd5b0ebcd986ff Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Mon, 20 Nov 2023 16:36:11 +0100 Subject: [PATCH] Another bunch of coverity fixes --- pdns/recursordist/filterpo.hh | 4 ++-- pdns/recursordist/reczones.cc | 4 ++-- pdns/recursordist/secpoll-recursor.cc | 2 +- pdns/recursordist/settings/cxxsupport.cc | 16 ++++++++-------- pdns/recursordist/validate-recursor.cc | 2 +- pdns/recursordist/ws-recursor.cc | 4 ++-- pdns/tcounters.hh | 1 + 7 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pdns/recursordist/filterpo.hh b/pdns/recursordist/filterpo.hh index b5aa306bf7..19bdcb8707 100644 --- a/pdns/recursordist/filterpo.hh +++ b/pdns/recursordist/filterpo.hh @@ -142,7 +142,7 @@ public: newZoneData = std::make_shared(); } newZoneData->d_name = name; - d_zoneData = newZoneData; + d_zoneData = std::move(newZoneData); } const std::unordered_set& getTags() const @@ -420,7 +420,7 @@ public: if (newZone) { assureZones(zoneIdx); newZone->setPriority(zoneIdx); - d_zones[zoneIdx] = newZone; + d_zones[zoneIdx] = std::move(newZone); } } diff --git a/pdns/recursordist/reczones.cc b/pdns/recursordist/reczones.cc index 8e09f19cbf..fa763cd9ad 100644 --- a/pdns/recursordist/reczones.cc +++ b/pdns/recursordist/reczones.cc @@ -335,7 +335,7 @@ static void processApiZonesFile(shared_ptr& newMap, shared static void processForwardZonesFile(shared_ptr& newMap, shared_ptr& newSet, Logr::log_t log) { - const auto filename = ::arg()["forward-zones-file"]; + const auto& filename = ::arg()["forward-zones-file"]; if (filename.empty()) { return; } @@ -493,7 +493,7 @@ static void processAllowNotifyFor(shared_ptr& newSet) static void processAllowNotifyForFile(shared_ptr& newSet, Logr::log_t log) { - const auto filename = ::arg()["allow-notify-for-file"]; + const auto& filename = ::arg()["allow-notify-for-file"]; if (filename.empty()) { return; } diff --git a/pdns/recursordist/secpoll-recursor.cc b/pdns/recursordist/secpoll-recursor.cc index 9c165cb821..b54ae7dc5c 100644 --- a/pdns/recursordist/secpoll-recursor.cc +++ b/pdns/recursordist/secpoll-recursor.cc @@ -89,7 +89,7 @@ void doSecPoll(time_t* last_secpoll, Logr::log_t log) return; } - g_security_message = security_message; + g_security_message = std::move(security_message); auto rlog = vlog->withValues("securitymessage", Logging::Loggable(g_security_message), "status", Logging::Loggable(security_status)); if (g_security_status != 1 && security_status == 1) { diff --git a/pdns/recursordist/settings/cxxsupport.cc b/pdns/recursordist/settings/cxxsupport.cc index 2e58343bf4..8a9e331ff5 100644 --- a/pdns/recursordist/settings/cxxsupport.cc +++ b/pdns/recursordist/settings/cxxsupport.cc @@ -95,7 +95,7 @@ void pdns::settings::rec::oldStyleForwardsFileToBridgeStruct(const std::string& } ::rust::Vec<::rust::String> addresses; stringtok(addresses, instructions, ",; "); - ForwardZone forwardzone{domain, addresses, recurse, allowNotify}; + ForwardZone forwardzone{domain, std::move(addresses), recurse, allowNotify}; vec.push_back(std::move(forwardzone)); } } @@ -320,7 +320,7 @@ pdns::settings::rec::YamlSettingsStatus pdns::settings::rec::readYamlSettings(co mergeYamlSubFile(yamlfile, yamlstruct, false, log); } yamlstruct.validate(); - settings = yamlstruct; + settings = std::move(yamlstruct); return YamlSettingsStatus::OK; } catch (const ::rust::Error& ex) { @@ -348,7 +348,7 @@ void pdns::settings::rec::readYamlAllowFromFile(const std::string& filename, ::r auto data = string(std::istreambuf_iterator(file), std::istreambuf_iterator()); auto yamlvec = pdns::rust::settings::rec::parse_yaml_string_to_allow_from(data); pdns::rust::settings::rec::validate_allow_from(filename, yamlvec); - vec = yamlvec; + vec = std::move(yamlvec); } void pdns::settings::rec::readYamlForwardZonesFile(const std::string& filename, ::rust::Vec& vec, Logr::log_t log) @@ -362,7 +362,7 @@ void pdns::settings::rec::readYamlForwardZonesFile(const std::string& filename, auto data = string(std::istreambuf_iterator(file), std::istreambuf_iterator()); auto yamlvec = pdns::rust::settings::rec::parse_yaml_string_to_forward_zones(data); pdns::rust::settings::rec::validate_forward_zones("forward_zones", yamlvec); - vec = yamlvec; + vec = std::move(yamlvec); } void pdns::settings::rec::readYamlAllowNotifyForFile(const std::string& filename, ::rust::Vec<::rust::String>& vec, Logr::log_t log) @@ -376,7 +376,7 @@ void pdns::settings::rec::readYamlAllowNotifyForFile(const std::string& filename auto data = string(std::istreambuf_iterator(file), std::istreambuf_iterator()); auto yamlvec = pdns::rust::settings::rec::parse_yaml_string_to_allow_notify_for(data); pdns::rust::settings::rec::validate_allow_notify_for("allow-notify-for", yamlvec); - vec = yamlvec; + vec = std::move(yamlvec); } std::string pdns::settings::rec::to_arg(const AuthZone& authzone) @@ -467,7 +467,7 @@ void pdns::settings::rec::to_yaml(::rust::Vec& field, const std::st boost::trim(headers.second); ::rust::Vec<::rust::String> addresses; stringtok(addresses, headers.second, " ;"); - ForwardZone forwardzone{headers.first, addresses, recurse, false}; + ForwardZone forwardzone{headers.first, std::move(addresses), recurse, false}; field.push_back(std::move(forwardzone)); } } @@ -521,7 +521,7 @@ static void processLine(const std::string& arg, FieldMap& map, bool mainFile) pdns::rust::settings::rec::Value rustvalue = {false, 0, 0.0, "", {}, {}, {}}; if (pdns::settings::rec::oldKVToBridgeStruct(var, val, section, fieldname, type_name, rustvalue)) { auto overriding = !mainFile && !incremental && !simpleRustType(type_name); - auto [existing, inserted] = map.emplace(std::pair{std::pair{section, fieldname}, pdns::rust::settings::rec::OldStyle{section, fieldname, var, type_name, rustvalue, overriding}}); + auto [existing, inserted] = map.emplace(std::pair{std::pair{section, fieldname}, pdns::rust::settings::rec::OldStyle{section, fieldname, var, std::move(type_name), rustvalue, overriding}}); if (!inserted) { // Simple values overwrite always existing->second.value.bool_val = rustvalue.bool_val; @@ -622,7 +622,7 @@ std::string pdns::settings::rec::defaultsToYaml() string name = var; string val = arg().getDefault(var); if (pdns::settings::rec::oldKVToBridgeStruct(name, val, section, fieldname, type_name, rustvalue)) { - map.emplace(std::pair{std::pair{section, fieldname}, pdns::rust::settings::rec::OldStyle{section, fieldname, name, type_name, rustvalue, false}}); + map.emplace(std::pair{std::pair{section, fieldname}, pdns::rust::settings::rec::OldStyle{section, fieldname, name, std::move(type_name), std::move(rustvalue), false}}); } } // Convert the map to a vector, as CXX does not have any dictionary like support. diff --git a/pdns/recursordist/validate-recursor.cc b/pdns/recursordist/validate-recursor.cc index 1a676792a9..d7f2b99c90 100644 --- a/pdns/recursordist/validate-recursor.cc +++ b/pdns/recursordist/validate-recursor.cc @@ -75,7 +75,7 @@ bool updateTrustAnchorsFromFile(const std::string& fname, map& } SLOG(g_log << Logger::Info << "Read changed Trust Anchors from file, updating" << endl, log->info(Logr::Info, "Read changed Trust Anchors from file, updating")); - dsAnchors = newDSAnchors; + dsAnchors = std::move(newDSAnchors); return true; } catch (const std::exception& e) { diff --git a/pdns/recursordist/ws-recursor.cc b/pdns/recursordist/ws-recursor.cc index 64c027da55..9baba3c5c6 100644 --- a/pdns/recursordist/ws-recursor.cc +++ b/pdns/recursordist/ws-recursor.cc @@ -260,7 +260,7 @@ static void doCreateZone(const Json& document) pdns::rust::settings::rec::AuthZone authzone; authzone.zone = zonename; authzone.file = zonefilename; - pdns::rust::settings::rec::api_add_auth_zone(yamlAPiZonesFile, authzone); + pdns::rust::settings::rec::api_add_auth_zone(yamlAPiZonesFile, std::move(authzone)); } else { apiWriteConfigFile(confbasename, "auth-zones+=" + zonename + "=" + zonefilename); @@ -275,7 +275,7 @@ static void doCreateZone(const Json& document) for (const auto& value : document["servers"].array_items()) { forward.forwarders.emplace_back(value.string_value()); } - pdns::rust::settings::rec::api_add_forward_zone(yamlAPiZonesFile, forward); + pdns::rust::settings::rec::api_add_forward_zone(yamlAPiZonesFile, std::move(forward)); } else { string serverlist; diff --git a/pdns/tcounters.hh b/pdns/tcounters.hh index 9689de4669..5225d725dd 100644 --- a/pdns/tcounters.hh +++ b/pdns/tcounters.hh @@ -151,6 +151,7 @@ public: } template + // coverity[auto_causes_copy] auto snapAt(Enum index) { return d_snapshot.lock()->at(index); -- 2.47.2