From eba0b1b4677f4e20ed4227160f363b0359afaac4 Mon Sep 17 00:00:00 2001 From: Vinicius Costa Gomes Date: Fri, 14 May 2010 20:03:34 -0300 Subject: [PATCH] obexd: Fix inverting the list with wrong search attribute When trying to use a search attribute that the contacts don't have we should fallback to using the default sorting algorithm (Indexed). --- obexd/plugins/pbap.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/obexd/plugins/pbap.c b/obexd/plugins/pbap.c index efa244534..25d5e242a 100644 --- a/obexd/plugins/pbap.c +++ b/obexd/plugins/pbap.c @@ -282,27 +282,24 @@ static int alpha_sort(gconstpointer a, gconstpointer b) return g_strcmp0(e1->name, e2->name); } -static int phonetical_sort(gconstpointer a, gconstpointer b) +static int indexed_sort(gconstpointer a, gconstpointer b) { const struct cache_entry *e1 = a; const struct cache_entry *e2 = b; - /* - * SOUND attribute is optinal. Keep the order - * when this attribute is not available. - */ - if (!e1->sound) - return 1; - - return g_strcmp0(e1->sound, e2->sound); + return (e1->handle - e2->handle); } -static int indexed_sort(gconstpointer a, gconstpointer b) +static int phonetical_sort(gconstpointer a, gconstpointer b) { const struct cache_entry *e1 = a; const struct cache_entry *e2 = b; - return (e1->handle - e2->handle); + /* SOUND attribute is optional. Use Indexed sort if not present. */ + if (!e1->sound || !e2->sound) + return indexed_sort(a, b); + + return g_strcmp0(e1->sound, e2->sound); } static GSList *sort_entries(GSList *l, uint8_t order, uint8_t search_attrib, -- 2.47.3