From: Sandro Santilli Date: Fri, 8 Sep 2017 21:46:17 +0000 (+0000) Subject: Do not call getPointxx_p on empty or null pointarray X-Git-Tag: 2.4.0rc1~30 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=76c89856a9d1a7d64289faca15a2aff37b565205;p=postgis Do not call getPointxx_p on empty or null pointarray Add more 0 returns on error git-svn-id: http://svn.osgeo.org/postgis/trunk@15671 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/lwpoint.c b/liblwgeom/lwpoint.c index 4cffe5743..5dfe57cc1 100644 --- a/liblwgeom/lwpoint.c +++ b/liblwgeom/lwpoint.c @@ -39,24 +39,24 @@ 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; }