From 4ed5f826c826a255897dbda2212a47b486cf0572 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 11 Oct 2021 14:47:52 +0200 Subject: QNetworkAccessAuthenticationManager: don't mix iterators and pointers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Timur Pocheptsov Reviewed-by: Volker Hilsheimer --- .../access/qnetworkaccessauthenticationmanager.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/network/access') 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::begin; + using QList::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::insert(++closestMatch, newCredential); else QList::insert(end(), newCredential); @@ -287,9 +290,9 @@ QNetworkAccessAuthenticationManager::fetchCachedCredentials(const QUrl &url, QNetworkAuthenticationCache *auth = static_cast(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; -- cgit v1.2.3