[pim/pimcommon] src/pimcommonakonadi/ldap: Fix potential crash

Laurent Montel <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 48622707a9fbcea662b834bf60ba3a53038a351f by Laurent Montel.
Committed on 28/07/2026 at 20:38.
Pushed by mlaurent into branch 'master'.

Fix potential crash

M  +4    -2    src/pimcommonakonadi/ldap/ldapsearchdialog.cpp

https://invent.kde.org/pim/pimcommon/-/commit/48622707a9fbcea662b834bf60ba3a53038a351f

diff --git a/src/pimcommonakonadi/ldap/ldapsearchdialog.cpp b/src/pimcommonakonadi/ldap/ldapsearchdialog.cpp
index 8ca91916..e49e6550 100644
--- a/src/pimcommonakonadi/ldap/ldapsearchdialog.cpp
+++ b/src/pimcommonakonadi/ldap/ldapsearchdialog.cpp
@@ -273,7 +273,8 @@ public:
             return {};
         }
 
-        return asUtf8(mContactList.at(index.row()).value(QStringLiteral("mail")).first()).trimmed();
+        const auto mailList = mContactList.at(index.row()).value(QStringLiteral("mail"));
+        return mailList.isEmpty() ? QString{} : asUtf8(mailList.constFirst()).trimmed();
     }
 
     [[nodiscard]] QString fullName(const QModelIndex &index) const
@@ -282,7 +283,8 @@ public:
             return {};
         }
 
-        return asUtf8(mContactList.at(index.row()).value(QStringLiteral("cn")).first()).trimmed();
+        const auto cnList = mContactList.at(index.row()).value(QStringLiteral("cn"));
+        return cnList.isEmpty() ? QString{} : asUtf8(cnList.constFirst()).trimmed();
     }
 
     void clear()
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.