Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-tidy: use std::min/max #14954

Merged
merged 3 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions pdns/dnspacket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "config.h"
#endif
#include "utility.hh"
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sys/types.h>
Expand Down Expand Up @@ -243,13 +244,11 @@ bool DNSPacket::couldBeCached() const

unsigned int DNSPacket::getMinTTL()
{
unsigned int minttl = UINT_MAX;
for(const DNSZoneRecord& rr : d_rrs) {
if (rr.dr.d_ttl < minttl)
minttl = rr.dr.d_ttl;
auto iter = std::min_element(d_rrs.begin(), d_rrs.end());
if (iter != d_rrs.end()) {
return iter->dr.d_ttl;
}

return minttl;
return UINT_MAX;
}

bool DNSPacket::isEmpty()
Expand Down
4 changes: 1 addition & 3 deletions pdns/dnsparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1016,9 +1016,7 @@ uint32_t getDNSPacketMinTTL(const char* packet, size_t length, bool* seenAuthSOA
}

const uint32_t ttl = dpm.get32BitInt();
if (result > ttl) {
result = ttl;
}
result = std::min(result, ttl);

dpm.skipRData();
}
Expand Down
4 changes: 4 additions & 0 deletions pdns/dnsparser.hh
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ struct DNSZoneRecord
bool auth{true};
bool disabled{false};
DNSRecord dr;

bool operator<(const DNSZoneRecord& other) const {
return dr.d_ttl < other.dr.d_ttl;
}
};

class UnknownRecordContent : public DNSRecordContent
Expand Down
18 changes: 7 additions & 11 deletions pdns/lua-record.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1096,18 +1096,14 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn
* @example ifportup(443, { '1.2.3.4', '5.4.3.2' })"
*/
lua.writeFunction("ifportup", [](int port, const boost::variant<iplist_t, ipunitlist_t>& ips, const boost::optional<std::unordered_map<string,string>> options) {
if (port < 0) {
port = 0;
}
if (port > std::numeric_limits<uint16_t>::max()) {
port = std::numeric_limits<uint16_t>::max();
}
port = std::max(port, 0);
port = std::min(port, static_cast<int>(std::numeric_limits<uint16_t>::max()));

auto checker = [](const ComboAddress& addr, const opts_t& opts) {
return g_up.isUp(addr, opts);
};
return genericIfUp(ips, options, checker, port);
});
auto checker = [](const ComboAddress& addr, const opts_t& opts) {
return g_up.isUp(addr, opts);
};
return genericIfUp(ips, options, checker, port);
});

lua.writeFunction("ifurlextup", [](const vector<pair<int, opts_t> >& ipurls, boost::optional<opts_t> options) {
vector<ComboAddress> candidates;
Expand Down
4 changes: 2 additions & 2 deletions pdns/sillyrecords.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "config.h"
#endif

#include <algorithm>
#include <boost/format.hpp>

#include "utility.hh"
Expand Down Expand Up @@ -46,8 +47,7 @@ static uint8_t precsize_aton(const char **strptr)
break;

mantissa = cmval / poweroften[exponent];
if (mantissa > 9)
mantissa = 9;
mantissa = std::min(mantissa, 9);

retval = (mantissa << 4) | exponent;

Expand Down
Loading