From: Paul Ramsey Date: Fri, 26 Jan 2018 14:55:44 +0000 (+0000) Subject: lwpoly_construct_circle: Avoid division by zero (Raúl Marín Rodríguez) X-Git-Tag: 2.4.4~25 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=79e92a391693942f06a399013fae54ce6d08f6d1;p=postgis lwpoly_construct_circle: Avoid division by zero (Raúl Marín Rodríguez) References #4003 git-svn-id: http://svn.osgeo.org/postgis/branches/2.4@16362 b70326c6-7e19-0410-871a-916f4a2858ee --- 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);