From: Raúl Marín Rodríguez Date: Mon, 1 Oct 2018 15:57:42 +0000 (+0000) Subject: Avoid division by zero in kmeans X-Git-Tag: 3.0.0alpha1~374 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=567ba507f485300e7f1f8cfd387533a9c5bc1e86;p=postgis Avoid division by zero in kmeans 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 --- diff --git a/NEWS b/NEWS index 8e5c6c41b..7423db1f3 100644 --- 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 diff --git a/liblwgeom/lwkmeans.c b/liblwgeom/lwkmeans.c index 360983daf..8a4931add 100644 --- a/liblwgeom/lwkmeans.c +++ b/liblwgeom/lwkmeans.c @@ -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]; + } } }