Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
[libcontacts] Prevent crash in coalescing import contacts. Fixes JB#1…
…2291

Remove obsolete contacts only after traversing indexed contact list.
  • Loading branch information
matthewvogt committed Nov 4, 2013
1 parent 379f7db commit 5da09cc
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/seasideimport.cpp
Expand Up @@ -306,13 +306,15 @@ QList<QContact> SeasideImport::buildImportContacts(const QList<QVersitDocument>

QList<QContact> importedContacts(importer.contacts());

QList<QList<QContact>::iterator> obsoleteContacts;

QHash<QString, QList<QContact>::iterator> importGuids;
QHash<QString, QList<QContact>::iterator> importNames;
QHash<QString, QList<QContact>::iterator> importLabels;

// Merge any duplicates in the import list
QList<QContact>::iterator it = importedContacts.begin();
while (it != importedContacts.end()) {
QList<QContact>::iterator it = importedContacts.begin(), end = importedContacts.end();
for ( ; it != end; ++it) {
QContact &contact(*it);

const QString guid = contact.detail<QContactGuid>().guid();
Expand Down Expand Up @@ -345,7 +347,7 @@ QList<QContact> SeasideImport::buildImportContacts(const QList<QVersitDocument>
if (previous) {
// Combine these duplicate contacts
mergeIntoExistingContact(previous, contact);
it = importedContacts.erase(it);
obsoleteContacts.prepend(it);
} else {
if (!guid.isEmpty()) {
importGuids.insert(guid, it);
Expand All @@ -360,11 +362,14 @@ QList<QContact> SeasideImport::buildImportContacts(const QList<QVersitDocument>
nickname.setNickname(label);
contact.saveDetail(&nickname);
}

++it;
}
}

// Remove contacts whose details were merged into other contacts
foreach (QList<QContact>::iterator it, obsoleteContacts) {
importedContacts.erase(it);
}

// Find all names and GUIDs for local contacts that might match these contacts
QContactFetchHint fetchHint(basicFetchHint());
#ifdef USING_QTPIM
Expand Down Expand Up @@ -398,8 +403,7 @@ QList<QContact> SeasideImport::buildImportContacts(const QList<QVersitDocument>
QMap<QContactId, QList<QContact>::iterator> existingIds;
QList<QList<QContact>::iterator> duplicates;

QList<QContact>::iterator end = importedContacts.end();
for (it = importedContacts.begin(); it != end; ++it) {
for (it = importedContacts.begin(), end = importedContacts.end(); it != end; ++it) {
const QString guid = (*it).detail<QContactGuid>().guid();

QContactId existingId;
Expand Down

0 comments on commit 5da09cc

Please sign in to comment.