[pim/trojita] src/Plugins/AkonadiAddressbook: Prevent potential crash and use cbegin/cend

Espen Sandøy Hustad <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 941111459fff4edd95036ffeec5a687cdee9d423 by Espen Sandøy Hustad.
Committed on 03/08/2026 at 19:00.
Pushed by ehustad into branch 'master'.

Prevent potential crash and use cbegin/cend

By not using functions returning iterators on
a temporary container. Fixes Clazy:
* warning: Don't call QList::begin() on temporary [-Wclazy-temporary-iterator]
* warning: Don't call QList::end() on temporary [-Wclazy-temporary-iterator]

M  +4    -3    src/Plugins/AkonadiAddressbook/AkonadiAddressbookCompletionJob.cpp

https://invent.kde.org/pim/trojita/-/commit/941111459fff4edd95036ffeec5a687cdee9d423

diff --git a/src/Plugins/AkonadiAddressbook/AkonadiAddressbookCompletionJob.cpp b/src/Plugins/AkonadiAddressbook/AkonadiAddressbookCompletionJob.cpp
index ffb7e946d..b307b76d9 100644
--- a/src/Plugins/AkonadiAddressbook/AkonadiAddressbookCompletionJob.cpp
+++ b/src/Plugins/AkonadiAddressbook/AkonadiAddressbookCompletionJob.cpp
@@ -67,10 +67,11 @@ void AkonadiAddressbookCompletionJob::searchResult(KJob *job)
         for (int i = 0; i < contacts.size() && (m_max == -1 || list.size() < m_max); ++i) {
             KContacts::Addressee contact = contacts[i];
 
+            const auto emails = contact.emails();
             // put the matching ones first and then the rest
-            QSet<QString> emailsSet(contact.emails().begin(), contact.emails().end());
-            QStringList emails1 = contact.emails().filter(m_input, Qt::CaseInsensitive);
-            const QSet<QString> emails1Set(emails1.begin(), emails1.end());
+            QSet<QString> emailsSet(emails.cbegin(), emails.cend());
+            QStringList emails1 = emails.filter(m_input, Qt::CaseInsensitive);
+            const QSet<QString> emails1Set(emails1.cbegin(), emails1.cend());
             QStringList emails2 = emailsSet.subtract(emails1Set).values();
 
             Q_FOREACH(const QString &email, emails1 + emails2) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.