From 0bf51769fe5177696ae10763a0f242b8a4104c70 Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Fri, 25 Jul 2025 15:00:13 +0200 Subject: [PATCH] Do not use countLabels() in chopOff() loop conditions. Instead, compute it once outside of the loop in a local variable and decrement that variable. Signed-off-by: Miod Vallat --- pdns/dnsname.cc | 4 ++-- pdns/dnssecinfra.cc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index 4316b39399..dcad68f931 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -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(); } } diff --git a/pdns/dnssecinfra.cc b/pdns/dnssecinfra.cc index 53309fbc40..d6826db6ca 100644 --- a/pdns/dnssecinfra.cc +++ b/pdns/dnssecinfra.cc @@ -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(); -- 2.47.2