bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

times: Fix tests


From: Bruno Haible
Subject: times: Fix tests
Date: Tue, 11 Dec 2018 20:40:36 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-138-generic; KDE/5.18.0; x86_64; ; )

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  <address@hidden>

        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

[Prev in Thread] Current Thread [Next in Thread]