]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit-reach: fix cast in compare_commits_by_gen()
authorRené Scharfe <l.s.r@web.de>
Mon, 1 Oct 2018 19:16:01 +0000 (21:16 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Oct 2018 22:57:47 +0000 (07:57 +0900)
The elements of the array to be sorted are commit pointers, so the
comparison function gets handed references to these pointers, not
pointers to commit objects.  Cast to the right type and dereference
once to correctly get the commit reference.

Found using Clang's ASan and t5500.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit-reach.c

index 5a845440a996a1f56f9c92d1ac86b96a727cbe8d..c6de0cc89cee8f914e8c272f2d70e64a76edb490 100644 (file)
@@ -526,8 +526,8 @@ int commit_contains(struct ref_filter *filter, struct commit *commit,
 
 static int compare_commits_by_gen(const void *_a, const void *_b)
 {
-       const struct commit *a = (const struct commit *)_a;
-       const struct commit *b = (const struct commit *)_b;
+       const struct commit *a = *(const struct commit * const *)_a;
+       const struct commit *b = *(const struct commit * const *)_b;
 
        if (a->generation < b->generation)
                return -1;