diff options
author | Ryan Lortie <desrt@desrt.ca> | 2013-10-04 23:12:26 -0400 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2013-10-04 23:12:26 -0400 |
commit | 8cf7ceb96fdbe03de79d0f16343513dbf142e6f6 (patch) | |
tree | 8896cf1db3980477a0727d55320d7a6681fc9c4b | |
parent | 2bb8dd2bb61bbcfe528ef7ff8dff78f328460369 (diff) |
Don't use strcmp with qsort
No matter how many times I make this mistake...
-rw-r--r-- | src/dfi-string-list.c | 9 | ||||
-rw-r--r-- | src/dfi-text-index.c | 9 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/dfi-string-list.c b/src/dfi-string-list.c index a4926dc..e9735fb 100644 --- a/src/dfi-string-list.c +++ b/src/dfi-string-list.c @@ -64,6 +64,13 @@ dfi_string_list_ensure (DfiStringList *string_list, g_hash_table_add (string_list->table, g_strdup (string)); } +static int +indirect_strcmp (gconstpointer a, + gconstpointer b) +{ + return strcmp (*(gchar **) a, *(gchar **) b); +} + void dfi_string_list_convert (DfiStringList *string_list) { @@ -84,7 +91,7 @@ dfi_string_list_convert (DfiStringList *string_list) g_assert_cmpint (i, ==, n); string_list->strings[n] = NULL; - qsort (string_list->strings, n, sizeof (char *), (GCompareFunc) strcmp); + qsort (string_list->strings, n, sizeof (char *), indirect_strcmp); /* Store the id of each string back into the table for fast lookup. * diff --git a/src/dfi-text-index.c b/src/dfi-text-index.c index 2f8e902..cb487ba 100644 --- a/src/dfi-text-index.c +++ b/src/dfi-text-index.c @@ -187,6 +187,13 @@ dfi_text_index_add_ids_tokenised (DfiTextIndex *text_index, } } +static int +indirect_strcmp (gconstpointer a, + gconstpointer b) +{ + return strcmp (*(gchar **) a, *(gchar **) b); +} + void dfi_text_index_convert (DfiTextIndex *text_index) { @@ -207,7 +214,7 @@ dfi_text_index_convert (DfiTextIndex *text_index) g_assert_cmpint (i, ==, n); text_index->tokens[n] = NULL; - qsort (text_index->tokens, n, sizeof (char *), (GCompareFunc) strcmp); + qsort (text_index->tokens, n, sizeof (char *), indirect_strcmp); } const gchar * const * |