From 5027b50adee47c3cbd99c6cc67ddb23340dbf2cd Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Mon, 23 Jul 2018 21:41:59 +0100 Subject: [PATCH] sort: ensure NaN will not trip over comp_double() In unlikely event of NaN being compared avoid exception. If NaN appears in input data it will be evaluated as equal with any value. Signed-off-by: Sami Kerola --- src/sort.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/sort.c b/src/sort.c index 4fdb4e0..2c3a05f 100644 --- a/src/sort.c +++ b/src/sort.c @@ -40,6 +40,7 @@ #include +#include #include #include #include @@ -118,9 +119,14 @@ int rangecomp(const void *restrict r1, const void *restrict r2) */ int comp_double(double f1, double f2) { - return f1 < f2 ? -1 : f1 > f2 ? 1 : 0; + if (isless(f1, f2)) + return -1; + else if (isless(f2, f1)) + return 1; + return 0; } + /*! \brief Compare two range_t by their first_ip. * \param r1,r2 Pointers to data to compare. * \return Like strcmp.