[postgis-tickets] r16859 - Avoid division by zero in kmeans

Raul raul at rmr.ninja
Mon Oct 1 08:55:50 PDT 2018


Author: algunenano
Date: 2018-10-01 08:55:50 -0700 (Mon, 01 Oct 2018)
New Revision: 16859

Modified:
   branches/2.5/NEWS
   branches/2.5/liblwgeom/lwkmeans.c
Log:
Avoid division by zero in kmeans

References #4188


Modified: branches/2.5/NEWS
===================================================================
--- branches/2.5/NEWS	2018-10-01 13:44:58 UTC (rev 16858)
+++ branches/2.5/NEWS	2018-10-01 15:55:50 UTC (rev 16859)
@@ -3,6 +3,7 @@
 
  * Bug fixes *
   - #4183, St_AsMVTGeom: Drop invalid geometries after simplification (Raúl Marín)
+  - #4188, Avoid division by zero in kmeans (Raúl Marín)
 
 PostGIS 2.5.0
 2018/09/23

Modified: branches/2.5/liblwgeom/lwkmeans.c
===================================================================
--- branches/2.5/liblwgeom/lwkmeans.c	2018-10-01 13:44:58 UTC (rev 16858)
+++ branches/2.5/liblwgeom/lwkmeans.c	2018-10-01 15:55:50 UTC (rev 16859)
@@ -85,8 +85,11 @@
 	}
 	for (i = 0; i < k; i++)
 	{
-		centers[i]->x /= weights[i];
-		centers[i]->y /= weights[i];
+		if (weights[i])
+		{
+			centers[i]->x /= weights[i];
+			centers[i]->y /= weights[i];
+		}
 	}
 }
 



More information about the postgis-tickets mailing list