Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeat Bolli <dev+git@drbeat.li>2018-07-09 22:25:36 +0300
committerJunio C Hamano <gitster@pobox.com>2018-07-10 00:37:50 +0300
commitb6d3f5a960c2b5dfe3d8d84e7f4c26e03d721d10 (patch)
tree6c20d9fd8dac366f5d3f6f130bbd7215f9546e64 /string-list.c
parent9ad36356dd13b53667a51020c9aef0d4e014af01 (diff)
string-list.c: avoid conversion from void * to function pointer
ISO C forbids the conversion of void pointers to function pointers. Introduce a context struct that encapsulates the function pointer. Signed-off-by: Beat Bolli <dev+git@drbeat.li> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'string-list.c')
-rw-r--r--string-list.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/string-list.c b/string-list.c
index a0cf0cfe88..771c455098 100644
--- a/string-list.c
+++ b/string-list.c
@@ -224,18 +224,28 @@ struct string_list_item *string_list_append(struct string_list *list,
list->strdup_strings ? xstrdup(string) : (char *)string);
}
+/*
+ * Encapsulate the compare function pointer because ISO C99 forbids
+ * casting from void * to a function pointer and vice versa.
+ */
+struct string_list_sort_ctx
+{
+ compare_strings_fn cmp;
+};
+
static int cmp_items(const void *a, const void *b, void *ctx)
{
- compare_strings_fn cmp = ctx;
+ struct string_list_sort_ctx *sort_ctx = ctx;
const struct string_list_item *one = a;
const struct string_list_item *two = b;
- return cmp(one->string, two->string);
+ return sort_ctx->cmp(one->string, two->string);
}
void string_list_sort(struct string_list *list)
{
- QSORT_S(list->items, list->nr, cmp_items,
- list->cmp ? list->cmp : strcmp);
+ struct string_list_sort_ctx sort_ctx = {list->cmp ? list->cmp : strcmp};
+
+ QSORT_S(list->items, list->nr, cmp_items, &sort_ctx);
}
struct string_list_item *unsorted_string_list_lookup(struct string_list *list,