[postgis-tickets] r15671 - Do not call getPointxx_p on empty or null pointarray
Daniel Baston
dbaston at gmail.com
Fri Sep 8 17:28:12 PDT 2017
Should callers be doing this type of checking themselves, instead of
incurring the penalty on all point access?
On Fri, Sep 8, 2017 at 5:46 PM, Sandro Santilli <strk at kbt.io> wrote:
> Author: strk
> Date: 2017-09-08 14:46:17 -0700 (Fri, 08 Sep 2017)
> New Revision: 15671
>
> Modified:
> trunk/liblwgeom/lwpoint.c
> Log:
> Do not call getPointxx_p on empty or null pointarray
>
> Add more 0 returns on error
>
> Modified: trunk/liblwgeom/lwpoint.c
> ===================================================================
> --- trunk/liblwgeom/lwpoint.c 2017-09-08 21:46:10 UTC (rev 15670)
> +++ trunk/liblwgeom/lwpoint.c 2017-09-08 21:46:17 UTC (rev 15671)
> @@ -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 @@
> {
> 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 @@
> {
> 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 @@
> {
> 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 @@
> {
> 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;
> }
>
> _______________________________________________
> postgis-tickets mailing list
> postgis-tickets at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/postgis-tickets
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-tickets/attachments/20170908/0b40c1e7/attachment.html>
More information about the postgis-tickets
mailing list