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 <timur.pocheptsov@qt.io>
This commit is contained in:
parent
fb1cf63d77
commit
5b9f4a7130
@ -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<QHstsPolicy> QHstsCache::policies() const
|
||||
{
|
||||
QVector<QHstsPolicy> values;
|
||||
values.reserve(knownHosts.size());
|
||||
values.reserve(int(knownHosts.size()));
|
||||
for (const auto &host : knownHosts)
|
||||
values << host;
|
||||
values << host.second;
|
||||
return values;
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,8 @@
|
||||
#include <QtCore/qglobal.h>
|
||||
#include <QtCore/qpair.h>
|
||||
#include <QtCore/qurl.h>
|
||||
#include <QtCore/qmap.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -117,7 +118,7 @@ private:
|
||||
QStringRef fragment;
|
||||
};
|
||||
|
||||
mutable QMap<HostName, QHstsPolicy> knownHosts;
|
||||
mutable std::map<HostName, QHstsPolicy> knownHosts;
|
||||
QHstsStore *hstsStore = nullptr;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user