Another wrong use of qsort(): The invocation of qsort in test-times.c is
invalid, with a function doublecmp that returns
   doublecmp (5, 6) = 1
   doublecmp (6, 5) = 0

POSIX [1] is not very clear about the requirements for a comparison
function passed to qsort, but it appears that a total order [2] is required.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/qsort.html
[2] https://en.wikipedia.org/wiki/Total_order


2018-12-11  Bruno Haible  <br...@clisp.org>

        times: Fix tests.
        * tests/test-times.c (doublecmp): Implement a total order.

diff --git a/tests/test-times.c b/tests/test-times.c
index eb069e4..7781e57 100644
--- a/tests/test-times.c
+++ b/tests/test-times.c
@@ -35,7 +35,7 @@ doublecmp (const void *p, const void *q)
   double a = *(double *) p;
   double b = *(double *) q;
 
-  return a < b;
+  return a < b ? -1 : a > b ? 1 : 0;
 }
 
 int


Reply via email to