diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2021-10-11 14:47:52 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2021-10-14 18:16:17 +0200 |
commit | 4ed5f826c826a255897dbda2212a47b486cf0572 (patch) | |
tree | ce3e732d466b16786e54819b5e23b5526b54ad9b /src/network/access/qnetworkaccessauthenticationmanager.cpp | |
parent | a47f66cee280cef1e5854f3ed187e9f2be19697a (diff) |
QNetworkAccessAuthenticationManager: don't mix iterators and pointers
QList::iterator is not a pointer and shouldn't be treated as one.
Convert the code to use iterators consistently (using iterators is
necessary due to the call to insert()).
Change-Id: I917b3ff6fdcf1f7959e35ac5b091a8140e9f833c
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/network/access/qnetworkaccessauthenticationmanager.cpp')
-rw-r--r-- | src/network/access/qnetworkaccessauthenticationmanager.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/network/access/qnetworkaccessauthenticationmanager.cpp b/src/network/access/qnetworkaccessauthenticationmanager.cpp index 4899273aa8..7b2e439fe3 100644 --- a/src/network/access/qnetworkaccessauthenticationmanager.cpp +++ b/src/network/access/qnetworkaccessauthenticationmanager.cpp @@ -62,20 +62,23 @@ public: reserve(1); } - QNetworkAuthenticationCredential *findClosestMatch(const QString &domain) + using QList<QNetworkAuthenticationCredential>::begin; + using QList<QNetworkAuthenticationCredential>::end; + + iterator findClosestMatch(const QString &domain) { iterator it = std::lower_bound(begin(), end(), domain); if (it == end() && !isEmpty()) --it; if (it == end() || !domain.startsWith(it->domain)) - return nullptr; - return &*it; + return end(); + return it; } void insert(const QString &domain, const QString &user, const QString &password) { - QNetworkAuthenticationCredential *closestMatch = findClosestMatch(domain); - if (closestMatch && closestMatch->domain == domain) { + iterator closestMatch = findClosestMatch(domain); + if (closestMatch != end() && closestMatch->domain == domain) { // we're overriding the current credentials closestMatch->user = user; closestMatch->password = password; @@ -85,7 +88,7 @@ public: newCredential.user = user; newCredential.password = password; - if (closestMatch) + if (closestMatch != end()) QList<QNetworkAuthenticationCredential>::insert(++closestMatch, newCredential); else QList<QNetworkAuthenticationCredential>::insert(end(), newCredential); @@ -287,9 +290,9 @@ QNetworkAccessAuthenticationManager::fetchCachedCredentials(const QUrl &url, QNetworkAuthenticationCache *auth = static_cast<QNetworkAuthenticationCache *>(authenticationCache.requestEntryNow(cacheKey)); - QNetworkAuthenticationCredential *cred = auth->findClosestMatch(url.path()); + auto cred = auth->findClosestMatch(url.path()); QNetworkAuthenticationCredential ret; - if (cred) + if (cred != auth->end()) ret = *cred; authenticationCache.releaseEntry(cacheKey); return ret; |