]> granicus.if.org Git - postgis/commitdiff
Avoid division by zero in kmeans
authorRaúl Marín Rodríguez <rmrodriguez@carto.com>
Mon, 1 Oct 2018 15:57:42 +0000 (15:57 +0000)
committerRaúl Marín Rodríguez <rmrodriguez@carto.com>
Mon, 1 Oct 2018 15:57:42 +0000 (15:57 +0000)
Closes #4188
Closes https://github.com/postgis/postgis/pull/309

git-svn-id: http://svn.osgeo.org/postgis/trunk@16860 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
liblwgeom/lwkmeans.c

diff --git a/NEWS b/NEWS
index 8e5c6c41bd5b4686f4a516630c13277d1bdc4087..7423db1f3c42ab33114044d3989b896ef1494f87 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,7 @@ PostGIS 3.0.0
   - #4176, ST_Intersects supports GEOMETRYCOLLECTION (Darafei Praliaskouski)
   - #4181, St_AsMVTGeom: Avoid type changes due to validation (Raúl Marín)
   - #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
index 360983daf95d2ef62f32d573cd65ba032351deaa..8a4931add2d75dcefc1b4617095cb24097326421 100644 (file)
@@ -82,8 +82,11 @@ update_means(POINT2D** objs, int* clusters, uint32_t n, POINT2D** centers, uint3
        }
        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];
+               }
        }
 }