]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Do not use countLabels() in chopOff() loop conditions. 15922/head
authorMiod Vallat <miod.vallat@powerdns.com>
Fri, 25 Jul 2025 13:00:13 +0000 (15:00 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Fri, 25 Jul 2025 13:02:42 +0000 (15:02 +0200)
Instead, compute it once outside of the loop in a local variable and
decrement that variable.

Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
pdns/dnsname.cc
pdns/dnssecinfra.cc

index 4316b393999e43db6debf6a40d96e8dd20dbd7ec..dcad68f931e4b4dec9540abfac4f9aecc4cfdca3 100644 (file)
@@ -632,8 +632,8 @@ unsigned int DNSName::countLabels() const
 
 void DNSName::trimToLabels(unsigned int to)
 {
-  while(countLabels() > to && chopOff()) {
-    ;
+  for (auto nlabels = countLabels(); nlabels > to; --nlabels) {
+    chopOff();
   }
 }
 
index 53309fbc40dd28028ae628ab8c5094e2dbc65087..d6826db6ca05f686e5cf7fc4b3989b924acdcd2c 100644 (file)
@@ -526,7 +526,7 @@ string getMessageForRRSET(const DNSName& qname, const RRSIGRecordContent& rrc, c
 
     if (rrsig_labels < fqdn_labels) {
       DNSName choppedQname(qname);
-      while (choppedQname.countLabels() > rrsig_labels) {
+      for (auto nlabels = fqdn_labels; nlabels > rrsig_labels; --nlabels) {
         choppedQname.chopOff();
       }
       nameToHash = "\x01*" + choppedQname.toDNSStringLC();