From: Miod Vallat Date: Mon, 13 Jul 2026 07:48:36 +0000 (+0200) Subject: Explain why we can't have nice things. X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=233d67450da5ae651144cef070d738bd24e7c8e5;p=thirdparty%2Fpdns.git Explain why we can't have nice things. Signed-off-by: Miod Vallat --- diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index ceecce807b..35bfbd4e00 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -491,6 +491,10 @@ struct SuffixMatchTree std::string_view d_name; bool operator<(const SuffixMatchTree& smt) const { + // This whole logic unfortunately can't be rewritten as + // pdns_ilexicographical_compare_three_way(this->d_name, smt.d_name) + // for, when the strings differ in length, the last return statement + // in the code below returns the opposite value. auto compareUpTo = std::min(this->d_name.size(), smt.d_name.size()); auto this_name = std::string_view(this->d_name.data(), compareUpTo); auto smt_name = std::string_view(smt.d_name.data(), compareUpTo); @@ -499,7 +503,7 @@ struct SuffixMatchTree return ret < 0; } if (this->d_name.size() == smt.d_name.size()) { - return ret < 0; + return 0; } return this->d_name.size() < smt.d_name.size(); } @@ -507,6 +511,10 @@ struct SuffixMatchTree bool operator<(const LightKey& lk) const { + // This whole logic unfortunately can't be rewritten as + // pdns_ilexicographical_compare_three_way(this->d_name, lk.d_name) + // for, when the strings differ in length, the last return statement + // in the code below returns the opposite value. auto compareUpTo = std::min(this->d_name.size(), lk.d_name.size()); auto this_name = std::string_view(this->d_name.data(), compareUpTo); auto lk_name = std::string_view(lk.d_name.data(), compareUpTo); @@ -515,7 +523,7 @@ struct SuffixMatchTree return ret < 0; } if (this->d_name.size() == lk.d_name.size()) { - return ret < 0; + return 0; } return this->d_name.size() < lk.d_name.size(); }