]> granicus.if.org Git - postgis/commitdiff
Do not call getPointxx_p on empty or null pointarray
authorSandro Santilli <strk@kbt.io>
Fri, 8 Sep 2017 21:46:17 +0000 (21:46 +0000)
committerSandro Santilli <strk@kbt.io>
Fri, 8 Sep 2017 21:46:17 +0000 (21:46 +0000)
Add more 0 returns on error

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

liblwgeom/lwpoint.c

index 4cffe5743a6ab3a5cd91f3a113ce772d9ac043b2..5dfe57cc17dc64dc529508fc2c6ad08374d04655 100644 (file)
 int
 lwpoint_getPoint2d_p(const LWPOINT *point, POINT2D *out)
 {
-       return getPoint2d_p(point->point, 0, out);
+       return lwpoint_is_empty(point) ? 0 : getPoint2d_p(point->point, 0, out);
 }
 
 /* convenience functions to hide the POINTARRAY */
 int
 lwpoint_getPoint3dz_p(const LWPOINT *point, POINT3DZ *out)
 {
-       return getPoint3dz_p(point->point,0,out);
+       return lwpoint_is_empty(point) ? 0 : getPoint3dz_p(point->point,0,out);
 }
 int
 lwpoint_getPoint3dm_p(const LWPOINT *point, POINT3DM *out)
 {
-       return getPoint3dm_p(point->point,0,out);
+       return lwpoint_is_empty(point) ? 0 : getPoint3dm_p(point->point,0,out);
 }
 int
 lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
 {
-       return getPoint4d_p(point->point,0,out);
+       return lwpoint_is_empty(point) ? 0 : getPoint4d_p(point->point,0,out);
 }
 
 double
@@ -64,7 +64,10 @@ lwpoint_get_x(const LWPOINT *point)
 {
        POINT4D pt;
        if ( lwpoint_is_empty(point) )
+       {
                lwerror("lwpoint_get_x called with empty geometry");
+               return 0;
+       }
        getPoint4d_p(point->point, 0, &pt);
        return pt.x;
 }
@@ -74,7 +77,10 @@ lwpoint_get_y(const LWPOINT *point)
 {
        POINT4D pt;
        if ( lwpoint_is_empty(point) )
+       {
                lwerror("lwpoint_get_y called with empty geometry");
+               return 0;
+       }
        getPoint4d_p(point->point, 0, &pt);
        return pt.y;
 }
@@ -84,9 +90,15 @@ lwpoint_get_z(const LWPOINT *point)
 {
        POINT4D pt;
        if ( lwpoint_is_empty(point) )
+       {
                lwerror("lwpoint_get_z called with empty geometry");
+               return 0;
+       }
        if ( ! FLAGS_GET_Z(point->flags) )
+       {
                lwerror("lwpoint_get_z called without z dimension");
+               return 0;
+       }
        getPoint4d_p(point->point, 0, &pt);
        return pt.z;
 }
@@ -96,9 +108,15 @@ lwpoint_get_m(const LWPOINT *point)
 {
        POINT4D pt;
        if ( lwpoint_is_empty(point) )
+       {
                lwerror("lwpoint_get_m called with empty geometry");
+               return 0;
+       }
        if ( ! FLAGS_GET_M(point->flags) )
+       {
                lwerror("lwpoint_get_m called without m dimension");
+               return 0;
+       }
        getPoint4d_p(point->point, 0, &pt);
        return pt.m;
 }