From: Paul Ramsey Date: Fri, 8 Sep 2017 21:09:53 +0000 (+0000) Subject: Change all PARANOIA blocks to throw errors instead of X-Git-Tag: 2.4.0rc1~34 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=156c109816b1c1b486c18f7b10c5ea042f773193;p=postgis Change all PARANOIA blocks to throw errors instead of quietly changing return values git-svn-id: http://svn.osgeo.org/postgis/trunk@15667 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/lwcollection.c b/liblwgeom/lwcollection.c index cfb6d923f..f1a1604d4 100644 --- a/liblwgeom/lwcollection.c +++ b/liblwgeom/lwcollection.c @@ -219,6 +219,7 @@ LWCOLLECTION* lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom) { if ( col->geoms[i] == geom ) { + lwerror("%s [%d] found duplicate geometry in collection %p == %p", __FILE__, __LINE__, col->geoms[i], geom); LWDEBUGF(4, "Found duplicate geometry in collection %p == %p", col->geoms[i], geom); return col; } diff --git a/liblwgeom/lwgeom_api.c b/liblwgeom/lwgeom_api.c index 0997725cd..01122259d 100644 --- a/liblwgeom/lwgeom_api.c +++ b/liblwgeom/lwgeom_api.c @@ -246,11 +246,15 @@ getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *op) int zmflag; #if PARANOIA_LEVEL > 0 - if ( ! pa ) lwerror("getPoint4d_p: NULL pointarray"); + if ( ! pa ) + { + lwerror("%s [%d] NULL POINTARRAY input", __FILE__, __LINE__); + return 0; + } if ( (n<0) || (n>=pa->npoints)) { - lwerror("getPoint4d_p: point offset out of range"); + lwerror("%s [%d] called with n=%d and npoints=%d", __FILE__, __LINE__, n, pa->npoints); return 0; } #endif @@ -335,12 +339,16 @@ getPoint3dz_p(const POINTARRAY *pa, int n, POINT3DZ *op) uint8_t *ptr; #if PARANOIA_LEVEL > 0 - if ( ! pa ) return 0; + if ( ! pa ) + { + lwerror("%s [%d] NULL POINTARRAY input", __FILE__, __LINE__); + return 0; + } if ( (n<0) || (n>=pa->npoints)) { - LWDEBUGF(4, "%d out of numpoint range (%d)", n, pa->npoints); - return 0; /*error */ + lwerror("%s [%d] called with n=%d and npoints=%d", __FILE__, __LINE__, n, pa->npoints); + return 0; } #endif @@ -386,12 +394,16 @@ getPoint3dm_p(const POINTARRAY *pa, int n, POINT3DM *op) int zmflag; #if PARANOIA_LEVEL > 0 - if ( ! pa ) return 0; + if ( ! pa ) + { + lwerror("%s [%d] NULL POINTARRAY input", __FILE__, __LINE__); + return 0; + } if ( (n<0) || (n>=pa->npoints)) { - lwerror("%d out of numpoint range (%d)", n, pa->npoints); - return 0; /*error */ + lwerror("%s [%d] called with n=%d and npoints=%d", __FILE__, __LINE__, n, pa->npoints); + return 0; } #endif @@ -462,12 +474,16 @@ int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point) { #if PARANOIA_LEVEL > 0 - if ( ! pa ) return 0; + if ( ! pa ) + { + lwerror("%s [%d] NULL POINTARRAY input", __FILE__, __LINE__); + return 0; + } if ( (n<0) || (n>=pa->npoints)) { - lwerror("getPoint2d_p: point offset out of range"); - return 0; /*error */ + lwerror("%s [%d] called with n=%d and npoints=%d", __FILE__, __LINE__, n, pa->npoints); + return 0; } #endif diff --git a/liblwgeom/lwgeom_geos.c b/liblwgeom/lwgeom_geos.c index dde69595a..14799810f 100644 --- a/liblwgeom/lwgeom_geos.c +++ b/liblwgeom/lwgeom_geos.c @@ -1250,7 +1250,7 @@ LWGEOM_GEOS_buildArea(const GEOSGeometry* geom_in) if ( GEOSGeomTypeId(geos_result) != COLLECTIONTYPE ) { GEOSGeom_destroy(geos_result); - lwerror("Unexpected return from GEOSpolygonize"); + lwerror("%s [%d] Unexpected return from GEOSpolygonize", __FILE__, __LINE__); return 0; } #endif @@ -1431,7 +1431,7 @@ lwgeom_buildarea(const LWGEOM *geom) #if PARANOIA_LEVEL > 0 if ( geom_out == NULL ) { - lwerror("serialization error"); + lwerror("%s [%s] serialization error", __FILE__, __LINE__); return NULL; } diff --git a/liblwgeom/lwgeom_geos_clean.c b/liblwgeom/lwgeom_geos_clean.c index a30e69646..5a6138a4e 100644 --- a/liblwgeom/lwgeom_geos_clean.c +++ b/liblwgeom/lwgeom_geos_clean.c @@ -964,7 +964,7 @@ LWGEOM_GEOS_makeValid(const GEOSGeometry* gin) GEOSGeom_destroy(pd); if ( loss ) { - lwnotice("Vertices lost in LWGEOM_GEOS_makeValid"); + lwnotice("%s [%d] Vertices lost in LWGEOM_GEOS_makeValid", __FILE__, __LINE__); /* return NULL */ } } diff --git a/liblwgeom/lwgeom_geos_split.c b/liblwgeom/lwgeom_geos_split.c index 3447aed0e..4e41a6764 100644 --- a/liblwgeom/lwgeom_geos_split.c +++ b/liblwgeom/lwgeom_geos_split.c @@ -397,16 +397,6 @@ lwpoly_split_by_line(const LWPOLY* lwpoly_in, const LWLINE* blade_in) return NULL; } - /* debugging.. - lwnotice("Bounds poly: %s", - lwgeom_to_ewkt(GEOS2LWGEOM(g1_bounds, hasZ))); - lwnotice("Line: %s", - lwgeom_to_ewkt(GEOS2LWGEOM(g2, hasZ))); - - lwnotice("Noded bounds: %s", - lwgeom_to_ewkt(GEOS2LWGEOM(vgeoms[0], hasZ))); - */ - polygons = GEOSPolygonize(vgeoms, 1); if ( NULL == polygons ) { @@ -426,7 +416,7 @@ lwpoly_split_by_line(const LWPOLY* lwpoly_in, const LWLINE* blade_in) GEOSGeom_destroy(g1_bounds); GEOSGeom_destroy((GEOSGeometry*)vgeoms[0]); GEOSGeom_destroy(polygons); - lwerror("Unexpected return from GEOSpolygonize"); + lwerror("%s [%s] Unexpected return from GEOSpolygonize", __FILE__, __LINE__); return 0; } #endif diff --git a/liblwgeom/lwout_wkt.c b/liblwgeom/lwout_wkt.c index e04db3c2a..5fbccb76b 100644 --- a/liblwgeom/lwout_wkt.c +++ b/liblwgeom/lwout_wkt.c @@ -160,7 +160,7 @@ static void lwline_to_wkt_sb(const LWLINE *line, stringbuffer_t *sb, int precisi return; } - ptarray_to_wkt_sb(line->points, sb, precision, variant); + ptarray_to_wkt_sb(line->points, sb, precision, variant); } /* diff --git a/liblwgeom/ptarray.c b/liblwgeom/ptarray.c index 102b2c1bd..9394534d8 100644 --- a/liblwgeom/ptarray.c +++ b/liblwgeom/ptarray.c @@ -564,14 +564,15 @@ ptarray_removePoint(POINTARRAY *pa, uint32_t which) #if PARANOIA_LEVEL > 0 if ( which > pa->npoints-1 ) { - lwerror("ptarray_removePoint: offset (%d) out of range (%d..%d)", + lwerror("%s [%d] offset (%d) out of range (%d..%d)", __FILE__, __LINE__, which, 0, pa->npoints-1); return NULL; } if ( pa->npoints < 3 ) { - lwerror("ptarray_removePointe: can't remove a point from a 2-vertex POINTARRAY"); + lwerror("%s [%d] can't remove a point from a 2-vertex POINTARRAY", __FILE__, __LINE__); + return NULL; } #endif @@ -1706,7 +1707,7 @@ getPoint_internal(const POINTARRAY *pa, int n) #if PARANOIA_LEVEL > 0 if ( pa == NULL ) { - lwerror("getPoint got NULL pointarray"); + lwerror("%s [%d] got NULL pointarray", __FILE__, __LINE__); return NULL; } @@ -1716,7 +1717,7 @@ getPoint_internal(const POINTARRAY *pa, int n) ( n > pa->npoints ) || ( n >= pa->maxpoints ) ) { - lwerror("getPoint_internal called outside of ptarray range (n=%d, pa.npoints=%d, pa.maxpoints=%d)",n,pa->npoints,pa->maxpoints); + lwerror("%s [%d] called outside of ptarray range (n=%d, pa.npoints=%d, pa.maxpoints=%d)", __FILE__, __LINE__, n, pa->npoints, pa->maxpoints); return NULL; /*error */ } #endif diff --git a/postgis/lwgeom_box3d.c b/postgis/lwgeom_box3d.c index e67b4387c..1a6a2c1a7 100644 --- a/postgis/lwgeom_box3d.c +++ b/postgis/lwgeom_box3d.c @@ -170,9 +170,7 @@ Datum BOX3D_to_BOX2D(PG_FUNCTION_ARGS) static void box3d_to_box_p(BOX3D *box, BOX *out) { -#if PARANOIA_LEVEL > 0 - if (box == NULL) return; -#endif + if ( ! box ) return; out->low.x = box->xmin; out->low.y = box->ymin;