From a5a4c9184d7b2a92c9a2f507009319ea9747bb30 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 15 Nov 2023 12:17:21 +0100 Subject: [PATCH] Fix compar_int 'uint64_t' - 'uint64_t' may overflow return type int. cf https://stackoverflow.com/questions/36681906/c-qsort-doesnt-seem-to-work-with-unsigned-long Thanks @xianglin1998 ! --- src/mfoc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mfoc.c b/src/mfoc.c index e2545be..9887553 100644 --- a/src/mfoc.c +++ b/src/mfoc.c @@ -1198,7 +1198,9 @@ uint32_t median(denonce d) int compar_int(const void *a, const void *b) { - return (*(uint64_t *)b - * (uint64_t *)a); + if (*(uint64_t *)b == *(uint64_t *)a) return 0; + if (*(uint64_t *)b < * (uint64_t *)a) return 1; + return -1; } // Compare countKeys structure