Skip to content

Commit

Permalink
Merge pull request #15198 from rgacogne/ddist-coverity-20250221
Browse files Browse the repository at this point in the history
dnsdist: Fix a few warnings from Coverity
  • Loading branch information
rgacogne authored Feb 21, 2025
2 parents 725f809 + 5526490 commit b4b2d01
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion pdns/dnsdistdist/bpf-filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -974,9 +974,10 @@ bool BPFFilter::supportsMatchAction(MatchAction action) const
return true;
}
return d_mapFormat == BPFFilter::MapFormat::WithActions;
#endif /* HAVE_EBPF */
#else
(void)action;
return false;
#endif /* HAVE_EBPF */
}

bool BPFFilter::isExternal() const
Expand Down
3 changes: 3 additions & 0 deletions pdns/dnsdistdist/dnsdist-lua-bindings-dnsquestion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ void setupLuaBindingsDNSQuestion([[maybe_unused]] LuaContext& luaCtx)
return empty;
}

// coverity[auto_causes_copy]
return *dnsQuestion.ids.qTag;
});

Expand Down Expand Up @@ -552,9 +553,11 @@ void setupLuaBindingsDNSQuestion([[maybe_unused]] LuaContext& luaCtx)

luaCtx.registerFunction<LuaAssociativeTable<std::string> (DNSQuestion::*)(void) const>("getHTTPHeaders", [](const DNSQuestion& dnsQuestion) {
if (dnsQuestion.ids.du) {
// coverity[auto_causes_copy]
return dnsQuestion.ids.du->getHTTPHeaders();
}
if (dnsQuestion.ids.doh3u) {
// coverity[auto_causes_copy]
return dnsQuestion.ids.doh3u->getHTTPHeaders();
}
return LuaAssociativeTable<std::string>();
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnsdistdist/dnsdist-lua-inspection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ void setupLuaInspection(LuaContext& luaCtx)
for (const auto& entry : histo) {
int stars = static_cast<int>(70.0 * entry.second / highest);
char value = '*';
if (stars == 0 && entry.second != 0) {
if (stars == 0 && entry.second != 0 && highest != 0.0) {
stars = 1; // you get 1 . to show something is there..
if (70.0 * entry.second / highest > 0.5) {
value = ':';
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnsdistdist/dnsdist-lua-rules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ static void mvRule(IdentifierTypeT chainIdentifier, unsigned int from, unsigned
auto subject = rules[from];
rules.erase(rules.begin() + from);
if (destination > rules.size()) {
rules.push_back(subject);
rules.push_back(std::move(subject));
}
else {
if (from < destination) {
Expand Down
4 changes: 2 additions & 2 deletions pdns/dnsdistdist/dnsdist-lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2226,7 +2226,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
if (getOptionalValue<decltype(customResponseHeaders)>(vars, "customResponseHeaders", customResponseHeaders) > 0) {
for (auto const& headerMap : customResponseHeaders) {
auto headerResponse = std::pair(boost::to_lower_copy(headerMap.first), headerMap.second);
frontend->d_customResponseHeaders.insert(headerResponse);
frontend->d_customResponseHeaders.insert(std::move(headerResponse));
}
}

Expand Down Expand Up @@ -3082,7 +3082,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
checkAllParametersConsumed("declareMetric", vars);
}
}
auto result = dnsdist::metrics::declareCustomMetric(name, type, description, customName, withLabels);
auto result = dnsdist::metrics::declareCustomMetric(name, type, description, std::move(customName), withLabels);
if (result) {
g_outputBuffer += *result + "\n";
errlog("Error in declareMetric: %s", *result);
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnsdistdist/dnsdist-metrics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static T& initializeOrGetMetric(const std::string_view& name, std::map<std::stri
auto metricEntry = metricEntries.find(combinationOfLabels);
if (metricEntry == metricEntries.end()) {
metricEntry = metricEntries.emplace(std::piecewise_construct, std::forward_as_tuple(combinationOfLabels), std::forward_as_tuple()).first;
g_stats.entries.write_lock()->emplace_back(Stats::EntryTriple{std::string(name), combinationOfLabels, &metricEntry->second.d_value});
g_stats.entries.write_lock()->emplace_back(Stats::EntryTriple{std::string(name), std::move(combinationOfLabels), &metricEntry->second.d_value});
}
return metricEntry->second;
}
Expand Down
4 changes: 2 additions & 2 deletions pdns/dnsdistdist/dnsdist-protobuf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ ProtoBufMetaKey::ProtoBufMetaKey(const std::string& key)
if (!typeIt->d_caseSensitive) {
boost::algorithm::to_lower(variable);
}
d_subKey = variable;
d_subKey = std::move(variable);
}
return;
}
Expand Down Expand Up @@ -383,7 +383,7 @@ const ProtoBufMetaKey::TypeContainer ProtoBufMetaKey::s_types = {
auto tag = key;
tag.append(":");
tag.append(value);
result.push_back(tag);
result.push_back(std::move(tag));
}
}
return result;
Expand Down

0 comments on commit b4b2d01

Please sign in to comment.