From fe443f0856885ece754da66684caeb0c482255a1 Mon Sep 17 00:00:00 2001 From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> Date: Tue, 27 Jun 2017 17:41:22 -0400 Subject: [PATCH] AccountModel: do proper sanity check in slotContactRemoved pointers used without checking for nullptr value. Change-Id: I63eb9b460b44264857ced9ae0aff9bbd634b241c --- src/accountmodel.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/accountmodel.cpp b/src/accountmodel.cpp index d8f5a677..3223d57e 100644 --- a/src/accountmodel.cpp +++ b/src/accountmodel.cpp @@ -556,12 +556,17 @@ AccountModelPrivate::slotContactAdded(const QString &accountID, const QString &u void AccountModelPrivate::slotContactRemoved(const QString &accountID, const QString &uri, bool banned) { - if (not banned) - return; - - auto account = q_ptr->getById(accountID.toLatin1()); - auto cm = PhoneDirectoryModel::instance().getNumber(uri, account); - account->bannedContactModel()->add(cm); + if (auto account = q_ptr->getById(accountID.toLatin1())) { + if (auto cm = PhoneDirectoryModel::instance().getNumber(uri, account)) { + auto& daemon_contacts = account->getContacts(); + // TODO: removeAll() is 5.4 - not yet supported by debian 8 + auto index = daemon_contacts.indexOf(cm); + if (index >= 0) + daemon_contacts.remove(index); + if (banned) + account->bannedContactModel()->add(cm); + } + } } ///Update accounts -- GitLab