commit-reach: fix cast in compare_commits_by_gen()

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>

René Scharfe committed Oct 1, 2018 at 21:16 UTC 8628ace2691510dc856e2a9c735706fa8f0620e1
1 file changed +2 -2
commit-reach.c
+2 -2
@@ -526,8 +526,8 @@ int commit_contains(struct ref_filter *filter, struct commit *commit,
526
527 static int compare_commits_by_gen(const void *_a, const void *_b)
528 {
529 - const struct commit *a = (const struct commit *)_a;
530 - const struct commit *b = (const struct commit *)_b;
529 + const struct commit *a = *(const struct commit * const *)_a;
530 + const struct commit *b = *(const struct commit * const *)_b;
531
532 if (a->generation < b->generation)
533 return -1;