From 5b9f4a7130fce7fe31ad7a6c916e629e13c9888f Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Mon, 23 Oct 2017 13:58:59 +0200 Subject: QHstsCache - do not mix const/non-const iterators Found by clazy (clazy-strict-iterators). QMap::find returns 'iterator' and this is what we need, since we need to modify the value referenced by this iterator. But QMap::insert only accepts 'const_iterator' and clazy warns about mixed const/non-const iterators (though actually QHstsCache does not have the original problem this check it trying to find). Since we do not share cache and do not want to try detaching on non-const access, we can use std::map which conveniently has 'insert' taking 'iterator' as its first parameter. As a bonus this will also fix another warning from clazy-range-loop check (when iterating over such a non-const map). Change-Id: Id82991cefce33723d177ed04058d15295e9b71d7 Reviewed-by: Timur Pocheptsov --- src/network/access/qhsts.cpp | 16 ++++++++-------- src/network/access/qhsts_p.h | 5 +++-- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/network/access/qhsts.cpp b/src/network/access/qhsts.cpp index 6a731afc2f..43a8a3663e 100644 --- a/src/network/access/qhsts.cpp +++ b/src/network/access/qhsts.cpp @@ -136,7 +136,7 @@ void QHstsCache::updateKnownHost(const QString &host, const QDateTime &expires, return; } - knownHosts.insert(pos, hostName, newPolicy); + knownHosts.insert(pos, {hostName, newPolicy}); if (hstsStore) hstsStore->addToObserved(newPolicy); return; @@ -144,8 +144,8 @@ void QHstsCache::updateKnownHost(const QString &host, const QDateTime &expires, if (newPolicy.isExpired()) knownHosts.erase(pos); - else if (*pos != newPolicy) - *pos = std::move(newPolicy); + else if (pos->second != newPolicy) + pos->second = std::move(newPolicy); else return; @@ -185,13 +185,13 @@ bool QHstsCache::isKnownHost(const QUrl &url) const while (nameToTest.fragment.size()) { auto const pos = knownHosts.find(nameToTest); if (pos != knownHosts.end()) { - if (pos.value().isExpired()) { + if (pos->second.isExpired()) { knownHosts.erase(pos); if (hstsStore) { // Inform our store that this policy has expired. - hstsStore->addToObserved(pos.value()); + hstsStore->addToObserved(pos->second); } - } else if (!superDomainMatch || pos.value().includesSubDomains()) { + } else if (!superDomainMatch || pos->second.includesSubDomains()) { return true; } } @@ -215,9 +215,9 @@ void QHstsCache::clear() QVector QHstsCache::policies() const { QVector values; - values.reserve(knownHosts.size()); + values.reserve(int(knownHosts.size())); for (const auto &host : knownHosts) - values << host; + values << host.second; return values; } diff --git a/src/network/access/qhsts_p.h b/src/network/access/qhsts_p.h index 2feb73b446..bc8708341d 100644 --- a/src/network/access/qhsts_p.h +++ b/src/network/access/qhsts_p.h @@ -61,7 +61,8 @@ #include #include #include -#include + +#include QT_BEGIN_NAMESPACE @@ -117,7 +118,7 @@ private: QStringRef fragment; }; - mutable QMap knownHosts; + mutable std::map knownHosts; QHstsStore *hstsStore = nullptr; }; -- cgit v1.2.3