]> granicus.if.org Git - postgis/commitdiff
lwpoly_construct_circle: Avoid division by zero (Raúl Marín Rodríguez)
authorPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 26 Jan 2018 15:01:15 +0000 (15:01 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 26 Jan 2018 15:01:15 +0000 (15:01 +0000)
Closes #4003
Closes #199

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

liblwgeom/lwpoly.c

index abfa4625a25562c64ff94c1a95bedcc0276feaa1..8f49d96ca558abfc8e96fb4caf9780b78501e4ee 100644 (file)
@@ -120,13 +120,13 @@ LWPOLY*
 lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
 {
        const uint32_t 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);