[postgis-tickets] r16583 - Inconsistent results from qsort callback (references #4093)

Paul Ramsey pramsey at cleverelephant.ca
Tue May 22 12:35:21 PDT 2018


Author: pramsey
Date: 2018-05-22 12:35:21 -0700 (Tue, 22 May 2018)
New Revision: 16583

Modified:
   trunk/liblwgeom/effectivearea.c
   trunk/liblwgeom/measures.c
Log:
Inconsistent results from qsort callback (references #4093)


Modified: trunk/liblwgeom/effectivearea.c
===================================================================
--- trunk/liblwgeom/effectivearea.c	2018-05-22 16:21:51 UTC (rev 16582)
+++ trunk/liblwgeom/effectivearea.c	2018-05-22 19:35:21 UTC (rev 16583)
@@ -112,7 +112,7 @@
 	if (v1==v2)
 		return (*(areanode**)a)-(*(areanode**)b);
 	else
-		return  (v1>v2 ) ? 1 : -1;
+		return  (v1 > v2) ? 1 : ((v1 < v2) ? -1 : 0);
 }
 
 

Modified: trunk/liblwgeom/measures.c
===================================================================
--- trunk/liblwgeom/measures.c	2018-05-22 16:21:51 UTC (rev 16582)
+++ trunk/liblwgeom/measures.c	2018-05-22 19:35:21 UTC (rev 16583)
@@ -2061,7 +2061,8 @@
 {
 	LISTSTRUCT *ia = (LISTSTRUCT*)a;
 	LISTSTRUCT *ib = (LISTSTRUCT*)b;
-	return ( ia->themeasure>ib->themeasure ) ? 1 : -1;
+	return 
+		(ia->themeasure > ib->themeasure) ? 1 : ((ia->themeasure < ib->themeasure) ? -1 : 0);
 }
 
 /**



More information about the postgis-tickets mailing list