From 79e92a391693942f06a399013fae54ce6d08f6d1 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Fri, 26 Jan 2018 14:55:44 +0000 Subject: [PATCH] =?utf8?q?lwpoly=5Fconstruct=5Fcircle:=20Avoid=20division?= =?utf8?q?=20by=20zero=20(Ra=C3=BAl=20Mar=C3=ADn=20Rodr=C3=ADguez)=20Refer?= =?utf8?q?ences=20#4003?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.osgeo.org/postgis/branches/2.4@16362 b70326c6-7e19-0410-871a-916f4a2858ee --- NEWS | 1 + liblwgeom/lwpoly.c | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index ada83ba4e..53f40b336 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ PostGIS 2.4.4dev * Bug fixes * - #3978, Fix KNN when upgrading from 2.1 or older (Sandro Santilli) - #4004, Avoid memory exhaustion when building a btree index (Edmund Horner) + - #4003, lwpoly_construct_circle: Avoid division by zero (Raúl Marín Rodríguez) PostGIS 2.3.6 2018/01/17 diff --git a/liblwgeom/lwpoly.c b/liblwgeom/lwpoly.c index bb8097c48..81135621e 100644 --- a/liblwgeom/lwpoly.c +++ b/liblwgeom/lwpoly.c @@ -120,13 +120,13 @@ LWPOLY* lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior) { const int segments = 4*segments_per_quarter; - const double theta = 2*M_PI / segments; + double theta; LWPOLY *lwpoly; POINTARRAY *pa; POINT4D pt; uint32_t i; - if (segments_per_quarter < 1) + if (segments_per_quarter == 0) { lwerror("Need at least one segment per quarter-circle."); return NULL; @@ -138,6 +138,8 @@ lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t se return NULL; } + theta = 2*M_PI / segments; + lwpoly = lwpoly_construct_empty(srid, LW_FALSE, LW_FALSE); pa = ptarray_construct_empty(LW_FALSE, LW_FALSE, segments + 1); -- 2.40.0