From a03a4f11e32d57afe46bb70d77f67321e0c835e3 Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Fri, 20 Jun 2025 10:19:38 +0200 Subject: [PATCH] burtleCI: add std::string wrapper --- pdns/burtle.hh | 5 +++++ pdns/dnsname.cc | 2 +- pdns/dnsname.hh | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pdns/burtle.hh b/pdns/burtle.hh index 53f8b8d017..65d1288354 100644 --- a/pdns/burtle.hh +++ b/pdns/burtle.hh @@ -178,3 +178,8 @@ inline uint32_t burtleCI(const unsigned char* k, uint32_t length, uint32_t initv /*-------------------------------------------- report the result */ return c; } + +inline uint32_t burtleCI(const std::string &k, uint32_t initval) +{ + return burtleCI(reinterpret_cast(k.data()), k.length(), initval); +} diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index 13c5cdb19e..dfc3841787 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -847,7 +847,7 @@ std::string ZoneName::toStringFull(const std::string& separator, const bool trai size_t ZoneName::hash(size_t init) const { if (!d_variant.empty()) { - init = burtleCI(reinterpret_cast(d_variant.data()), d_variant.length(), init); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast): can't static_cast because of sign difference + init = burtleCI(d_variant, init); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast): can't static_cast because of sign difference } return d_name.hash(init); diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index 630e9be4d8..6880fdfd45 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -153,7 +153,7 @@ public: void trimToLabels(unsigned int); size_t hash(size_t init=0) const { - return burtleCI((const unsigned char*)d_storage.c_str(), d_storage.size(), init); + return burtleCI(d_storage, init); } DNSName& operator+=(const DNSName& rhs) { -- 2.47.2