From: Remi Gacogne Date: Wed, 6 Jan 2021 09:25:12 +0000 (+0100) Subject: Only call std::string::reserve() when needed in hashQNameWithSalt() X-Git-Tag: dnsdist-1.6.0-alpha1^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2e730183d4a5dec3c601f8228ce9bb22f241598;p=thirdparty%2Fpdns.git Only call std::string::reserve() when needed in hashQNameWithSalt() --- diff --git a/pdns/dnssecinfra.cc b/pdns/dnssecinfra.cc index 152fd3bf80..110f5f1dfa 100644 --- a/pdns/dnssecinfra.cc +++ b/pdns/dnssecinfra.cc @@ -494,9 +494,6 @@ string hashQNameWithSalt(const std::string& salt, unsigned int iterations, const unsigned int times = iterations; unsigned char hash[SHA_DIGEST_LENGTH]; string toHash(qname.toDNSStringLC() + salt); - if (toHash.capacity() < (salt.size() + sizeof(hash))) { - toHash.reserve(salt.size() + sizeof(hash)); - } for (;;) { /* so the first time we hash the (lowercased) qname plus the salt, @@ -511,6 +508,9 @@ string hashQNameWithSalt(const std::string& salt, unsigned int iterations, const /* first time, we need to replace the qname + salt with the hash plus salt, since the qname will not likely match the size of the hash */ + if (toHash.capacity() < (sizeof(hash) + salt.size())) { + toHash.reserve(sizeof(hash) + salt.size()); + } toHash.assign(reinterpret_cast(hash), sizeof(hash)); toHash.append(salt); }