From 567ba507f485300e7f1f8cfd387533a9c5bc1e86 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ra=C3=BAl=20Mar=C3=ADn=20Rodr=C3=ADguez?= Date: Mon, 1 Oct 2018 15:57:42 +0000 Subject: [PATCH] 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 --- NEWS | 1 + liblwgeom/lwkmeans.c | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) 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]; + } } } -- 2.40.0