]> granicus.if.org Git - postgis/commitdiff
Fix #112: ST_CurveToLine sometimes crashes server. While the circle segmentiser detec...
authorMark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
Wed, 8 Jul 2009 04:59:19 +0000 (04:59 +0000)
committerMark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
Wed, 8 Jul 2009 04:59:19 +0000 (04:59 +0000)
 NULL pointer returned in this case. Since we are converting to a line, the current behaviour is to simply append the circle points as s
tandard line points.

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

liblwgeom/lwsegmentize.c

index 4cfe4fb3de8833b13bf5deca57f23b32f6afd52e..b02f1a2f3461bad3db43c7e4faa5291fd536dbf8 100644 (file)
@@ -165,14 +165,16 @@ lwcircle_segmentize(POINT4D *p1, POINT4D *p2, POINT4D *p3, uint32 perQuad)
        LWDEBUG(2, "lwcircle_segmentize called. ");
 
        radius = lwcircle_center(p1, p2, p3, &center);
-
-       LWDEBUGF(3, "lwcircle_segmentize, (%.16f, %.16f) radius=%.16f", center->x, center->y, radius);
-
        if (radius < 0)
        {
+               /* No center because points are colinear */
+               LWDEBUGF(3, "lwcircle_segmentize, (NULL) radius=%.16f", radius);
+
                return NULL;
        }
 
+       LWDEBUGF(3, "lwcircle_segmentize, (%.16f, %.16f) radius=%.16f", center->x, center->y, radius);
+
        a1 = atan2(p1->y - center->y, p1->x - center->x);
        a2 = atan2(p2->y - center->y, p2->x - center->x);
        a3 = atan2(p3->y - center->y, p3->x - center->x);
@@ -311,14 +313,28 @@ lwcurve_segmentize(LWCIRCSTRING *icurve, uint32 perQuad)
                getPoint4d_p(icurve->points, i, p3);
                tmp = lwcircle_segmentize(p1, p2, p3, perQuad);
 
-               LWDEBUGF(3, "lwcurve_segmentize: generated %d points", tmp->npoints);
+               if (tmp)
+               {
+                       LWDEBUGF(3, "lwcurve_segmentize: generated %d points", tmp->npoints);
 
-               for (j = 0; j < tmp->npoints; j++)
+                       for (j = 0; j < tmp->npoints; j++)
+                       {
+                               getPoint4d_p(tmp, j, p4);
+                               dynptarray_addPoint4d(ptarray, p4, 1);
+                       }
+                       lwfree(tmp);
+               }
+               else
                {
-                       getPoint4d_p(tmp, j, p4);
-                       dynptarray_addPoint4d(ptarray, p4, 1);
+                       LWDEBUG(3, "lwcurve_segmentize: points are colinear, returning curve points as line");
+
+                       for (j = i - 1 ; j <= i ; j++)
+                       {
+                               getPoint4d_p(icurve->points, j, p4);
+                               dynptarray_addPoint4d(ptarray, p4, 1);
+                       }
                }
-               lwfree(tmp);
+
        }
        oline = lwline_construct(icurve->SRID, NULL, ptarray_clone(ptarray->pa));