From 10f37fdc2389c572fbd4e330b6047832239670b7 Mon Sep 17 00:00:00 2001 From: David Blasby Date: Fri, 29 Jun 2001 22:32:53 +0000 Subject: [PATCH] Fixed bug: must ALWAYS copy input data - never modify it in place. If you do, it'll (unexpectly) update the database. git-svn-id: http://svn.osgeo.org/postgis/trunk@14 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis_fn.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/postgis_fn.c b/postgis_fn.c index 4ca4cd3e0..6e462f8f5 100644 --- a/postgis_fn.c +++ b/postgis_fn.c @@ -891,9 +891,13 @@ PG_FUNCTION_INFO_V1(force_2d); Datum force_2d(PG_FUNCTION_ARGS) { GEOMETRY *geom = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + GEOMETRY *result; - geom->is3d = FALSE; - PG_RETURN_POINTER(geom); + result = (GEOMETRY *) palloc(geom->size); + memcpy(result,geom, geom->size); + + result->is3d = FALSE; + PG_RETURN_POINTER(result); } @@ -901,9 +905,13 @@ PG_FUNCTION_INFO_V1(force_3d); Datum force_3d(PG_FUNCTION_ARGS) { GEOMETRY *geom = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + GEOMETRY *result; + + result = (GEOMETRY *) palloc(geom->size); + memcpy(result,geom, geom->size); - geom->is3d = TRUE; - PG_RETURN_POINTER(geom); + result->is3d = TRUE; + PG_RETURN_POINTER(result); } @@ -929,12 +937,20 @@ Datum combine_bbox(PG_FUNCTION_ARGS) if (box3d_ptr == NULL) { geom = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); - PG_RETURN_POINTER(&(geom->bvol)); // combine_bbox(null, geometry) => geometry->bvol + + box = (BOX3D *) palloc(sizeof(BOX3D)); + memcpy(box, &(geom->bvol), sizeof(BOX3D) ); + + PG_RETURN_POINTER(box); // combine_bbox(null, geometry) => geometry->bvol } if (geom_ptr == NULL) { - PG_RETURN_POINTER( PG_GETARG_DATUM(0) ); // combine_bbox(BOX3D, null) => BOX3D + box = (BOX3D *) palloc(sizeof(BOX3D)); + memcpy(box, (char *) PG_GETARG_DATUM(0) , sizeof(BOX3D) ); + + + PG_RETURN_POINTER( box ); // combine_bbox(BOX3D, null) => BOX3D } //combine_bbox(BOX3D, geometry) => union(BOX3D, geometry->bvol) @@ -1426,10 +1442,15 @@ Datum geometryn_collection(PG_FUNCTION_ARGS) PG_FUNCTION_INFO_V1(force_collection); Datum force_collection(PG_FUNCTION_ARGS) { - GEOMETRY *geom = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + GEOMETRY *geom = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + GEOMETRY *result; + + result = (GEOMETRY *) palloc(geom->size); + memcpy(result,geom, geom->size); + + result->type = COLLECTIONTYPE; - geom->type = COLLECTIONTYPE; - PG_RETURN_POINTER(geom); + PG_RETURN_POINTER(result); } -- 2.40.0