r16362 - lwpoly_construct_circle: Avoid division by zero (Raúl Marín Rodríguez)

Paul Ramsey pramsey at cleverelephant.ca
Fri Jan 26 06:55:44 PST 2018


Author: pramsey
Date: 2018-01-26 06:55:44 -0800 (Fri, 26 Jan 2018)
New Revision: 16362

Modified:
   branches/2.4/NEWS
   branches/2.4/liblwgeom/lwpoly.c
Log:
lwpoly_construct_circle: Avoid division by zero (Raúl Marín Rodríguez)
References #4003


Modified: branches/2.4/NEWS
===================================================================
--- branches/2.4/NEWS	2018-01-26 12:47:38 UTC (rev 16361)
+++ branches/2.4/NEWS	2018-01-26 14:55:44 UTC (rev 16362)
@@ -4,6 +4,7 @@
  * 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

Modified: branches/2.4/liblwgeom/lwpoly.c
===================================================================
--- branches/2.4/liblwgeom/lwpoly.c	2018-01-26 12:47:38 UTC (rev 16361)
+++ branches/2.4/liblwgeom/lwpoly.c	2018-01-26 14:55:44 UTC (rev 16362)
@@ -120,13 +120,13 @@
 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 @@
 		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);
 



More information about the postgis-tickets mailing list