<div dir="ltr">Should callers be doing this type of checking themselves, instead of incurring the penalty on all point access?</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 8, 2017 at 5:46 PM, Sandro Santilli <span dir="ltr"><<a href="mailto:strk@kbt.io" target="_blank">strk@kbt.io</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: strk<br>
Date: 2017-09-08 14:46:17 -0700 (Fri, 08 Sep 2017)<br>
New Revision: 15671<br>
<br>
Modified:<br>
   trunk/liblwgeom/lwpoint.c<br>
Log:<br>
Do not call getPointxx_p on empty or null pointarray<br>
<br>
Add more 0 returns on error<br>
<br>
Modified: trunk/liblwgeom/lwpoint.c<br>
==============================<wbr>==============================<wbr>=======<br>
--- trunk/liblwgeom/lwpoint.c   2017-09-08 21:46:10 UTC (rev 15670)<br>
+++ trunk/liblwgeom/lwpoint.c   2017-09-08 21:46:17 UTC (rev 15671)<br>
@@ -39,24 +39,24 @@<br>
 int<br>
 lwpoint_getPoint2d_p(const LWPOINT *point, POINT2D *out)<br>
 {<br>
-       return getPoint2d_p(point->point, 0, out);<br>
+       return lwpoint_is_empty(point) ? 0 : getPoint2d_p(point->point, 0, out);<br>
 }<br>
<br>
 /* convenience functions to hide the POINTARRAY */<br>
 int<br>
 lwpoint_getPoint3dz_p(const LWPOINT *point, POINT3DZ *out)<br>
 {<br>
-       return getPoint3dz_p(point->point,0,<wbr>out);<br>
+       return lwpoint_is_empty(point) ? 0 : getPoint3dz_p(point->point,0,<wbr>out);<br>
 }<br>
 int<br>
 lwpoint_getPoint3dm_p(const LWPOINT *point, POINT3DM *out)<br>
 {<br>
-       return getPoint3dm_p(point->point,0,<wbr>out);<br>
+       return lwpoint_is_empty(point) ? 0 : getPoint3dm_p(point->point,0,<wbr>out);<br>
 }<br>
 int<br>
 lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)<br>
 {<br>
-       return getPoint4d_p(point->point,0,<wbr>out);<br>
+       return lwpoint_is_empty(point) ? 0 : getPoint4d_p(point->point,0,<wbr>out);<br>
 }<br>
<br>
 double<br>
@@ -64,7 +64,10 @@<br>
 {<br>
        POINT4D pt;<br>
        if ( lwpoint_is_empty(point) )<br>
+       {<br>
                lwerror("lwpoint_get_x called with empty geometry");<br>
+               return 0;<br>
+       }<br>
        getPoint4d_p(point->point, 0, &pt);<br>
        return pt.x;<br>
 }<br>
@@ -74,7 +77,10 @@<br>
 {<br>
        POINT4D pt;<br>
        if ( lwpoint_is_empty(point) )<br>
+       {<br>
                lwerror("lwpoint_get_y called with empty geometry");<br>
+               return 0;<br>
+       }<br>
        getPoint4d_p(point->point, 0, &pt);<br>
        return pt.y;<br>
 }<br>
@@ -84,9 +90,15 @@<br>
 {<br>
        POINT4D pt;<br>
        if ( lwpoint_is_empty(point) )<br>
+       {<br>
                lwerror("lwpoint_get_z called with empty geometry");<br>
+               return 0;<br>
+       }<br>
        if ( ! FLAGS_GET_Z(point->flags) )<br>
+       {<br>
                lwerror("lwpoint_get_z called without z dimension");<br>
+               return 0;<br>
+       }<br>
        getPoint4d_p(point->point, 0, &pt);<br>
        return pt.z;<br>
 }<br>
@@ -96,9 +108,15 @@<br>
 {<br>
        POINT4D pt;<br>
        if ( lwpoint_is_empty(point) )<br>
+       {<br>
                lwerror("lwpoint_get_m called with empty geometry");<br>
+               return 0;<br>
+       }<br>
        if ( ! FLAGS_GET_M(point->flags) )<br>
+       {<br>
                lwerror("lwpoint_get_m called without m dimension");<br>
+               return 0;<br>
+       }<br>
        getPoint4d_p(point->point, 0, &pt);<br>
        return pt.m;<br>
 }<br>
<br>
______________________________<wbr>_________________<br>
postgis-tickets mailing list<br>
<a href="mailto:postgis-tickets@lists.osgeo.org">postgis-tickets@lists.osgeo.<wbr>org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-tickets" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/postgis-<wbr>tickets</a></blockquote></div><br></div>