aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJari Urpalainen <jari.urpalainen@nokia.com>2011-03-08 21:51:24 +0800
committerMatthew Barnes <mbarnes@redhat.com>2011-03-08 21:51:24 +0800
commita654e38eca0d6cead861e1d78285d3ecfb4925a0 (patch)
treee04d27f0e86a468e97cb093ff92c3edc04659f52
parentcbcae0eef22d80d564145de68fd55e47d2c35b05 (diff)
downloadgsoc2013-evolution-a654e38eca0d6cead861e1d78285d3ecfb4925a0.tar.gz
gsoc2013-evolution-a654e38eca0d6cead861e1d78285d3ecfb4925a0.tar.zst
gsoc2013-evolution-a654e38eca0d6cead861e1d78285d3ecfb4925a0.zip
Bug 644194 - EAddressbookModel: Logic error in remove_contact()
-rw-r--r--addressbook/gui/widgets/e-addressbook-model.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/addressbook/gui/widgets/e-addressbook-model.c b/addressbook/gui/widgets/e-addressbook-model.c
index 785be1c49e..6f679a4233 100644
--- a/addressbook/gui/widgets/e-addressbook-model.c
+++ b/addressbook/gui/widgets/e-addressbook-model.c
@@ -179,10 +179,20 @@ create_contact (EBookView *book_view,
update_folder_bar_message (model);
}
+static gint
+sort_descending (gconstpointer ca,
+ gconstpointer cb)
+{
+ gint a = *((gint *) ca);
+ gint b = *((gint *) cb);
+
+ return (a == b) ? 0 : (a < b) ? 1 : -1;
+}
+
static void
remove_contact (EBookView *book_view,
- GList *ids,
- EAddressbookModel *model)
+ GList *ids,
+ EAddressbookModel *model)
{
/* XXX we should keep a hash around instead of this O(n*m) loop */
GList *iter;
@@ -217,6 +227,11 @@ remove_contact (EBookView *book_view,
}
}
+ /* Sort the 'indices' array in descending order, since
+ * g_ptr_array_remove_index() shifts subsequent elements
+ * down one position to fill the gap. */
+ g_array_sort (indices, sort_descending);
+
for (ii = 0; ii < indices->len; ii++) {
gint index;
@@ -232,8 +247,8 @@ remove_contact (EBookView *book_view,
static void
modify_contact (EBookView *book_view,
- const GList *contact_list,
- EAddressbookModel *model)
+ const GList *contact_list,
+ EAddressbookModel *model)
{
GPtrArray *array;
@@ -247,15 +262,19 @@ modify_contact (EBookView *book_view,
target_uid = e_contact_get_const (contact, E_CONTACT_UID);
for (ii = 0; ii < array->len; ii++) {
+ EContact *contact;
const gchar *uid;
- uid = e_contact_get_const (
- array->pdata[ii], E_CONTACT_UID);
+ contact = array->pdata[ii];
+ g_return_if_fail (contact != NULL);
+
+ uid = e_contact_get_const (contact, E_CONTACT_UID);
+ g_return_if_fail (uid != NULL);
if (strcmp (uid, target_uid) != 0)
continue;
- g_object_unref (array->pdata[ii]);
+ g_object_unref (contact);
contact = e_contact_duplicate (contact);
array->pdata[ii] = contact;