]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
clang-tidy: use std::min/max
authorRosen Penev <rosenp@gmail.com>
Mon, 9 Dec 2024 00:58:46 +0000 (16:58 -0800)
committerRosen Penev <rosenp@gmail.com>
Thu, 19 Dec 2024 00:45:49 +0000 (16:45 -0800)
Found with readability-use-std-min-max

Signed-off-by: Rosen Penev <rosenp@gmail.com>
pdns/dnspacket.cc
pdns/dnsparser.cc
pdns/lua-record.cc
pdns/sillyrecords.cc

index 8588f2c21a151990792e98d6d195e0dedbd553d3..2afde53a3596469a0b7c626fdf171ae5910a5ea8 100644 (file)
@@ -23,6 +23,7 @@
 #include "config.h"
 #endif
 #include "utility.hh"
+#include <algorithm>
 #include <cstdio>
 #include <cstdlib>
 #include <sys/types.h>
@@ -245,8 +246,7 @@ 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;
+    minttl = std::min(minttl, rr.dr.d_ttl);
   }
 
   return minttl;
index 12974ae57cea70ad50361f967ed89aa271396f53..8a248587d78e114b935f6eea93b317ede9fd36c0 100644 (file)
@@ -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();
     }
index 1f2344a881b5e06c70a8d8a6999dc28ca0fdc020..b06c163061cd2fdffd97b578241de77f02c81925 100644 (file)
@@ -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;
index cc04a3c29f390bbd49c53fc7b01179a9a7752260..a6edc189e2903af18cdcabaf481e3aeb4d05c95a 100644 (file)
@@ -2,6 +2,7 @@
 #include "config.h"
 #endif
 
+#include <algorithm>
 #include <boost/format.hpp>
 
 #include "utility.hh"
@@ -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;