aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-09-19 17:31:17 +0200
committerMax Kellermann <max@duempel.org>2008-09-19 17:31:17 +0200
commit45b554123c08f36de1daf133164f76154045c387 (patch)
tree57d3a78d39098b5a2246e29f92066457aab357d1
parent7e9bee742cc8e7cc8d47f3a56466337d6d3a8efd (diff)
downloadmpd-45b554123c08f36de1daf133164f76154045c387.tar.gz
mpd-45b554123c08f36de1daf133164f76154045c387.tar.xz
mpd-45b554123c08f36de1daf133164f76154045c387.zip
filelist: fix segfault during filelist_sort()
When I converted the filelist from GList to GPtrArray, I missed that the GCompareFunc does not actually get the pointers from g_ptr_array_sort(), but pointers to the pointers... run g_ptr_array_sort_with_data() instead with a wrapper function.
-rw-r--r--src/filelist.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/filelist.c b/src/filelist.c
index 6e4ebed55..59fed4702 100644
--- a/src/filelist.c
+++ b/src/filelist.c
@@ -101,10 +101,22 @@ filelist_move(struct filelist *filelist, struct filelist *from)
g_ptr_array_set_size(from->entries, 0);
}
+static gint
+filelist_compare_indirect(gconstpointer ap, gconstpointer bp, gpointer data)
+{
+ GCompareFunc compare_func = data;
+ gconstpointer a = *(const gconstpointer*)ap;
+ gconstpointer b = *(const gconstpointer*)bp;
+
+ return compare_func(a, b);
+}
+
void
filelist_sort(struct filelist *filelist, GCompareFunc compare_func)
{
- g_ptr_array_sort(filelist->entries, compare_func);
+ g_ptr_array_sort_with_data(filelist->entries,
+ filelist_compare_indirect,
+ compare_func);
}
struct filelist_entry *