From: Paul Ramsey Date: Fri, 27 Jan 2012 22:24:44 +0000 (+0000) Subject: #1504 (Segfault running ST_EstimatedExtent()) X-Git-Tag: 2.0.0alpha3~48 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=75a855f404ddda6fe1698c8db6ab2c83c3391177;p=postgis #1504 (Segfault running ST_EstimatedExtent()) git-svn-id: http://svn.osgeo.org/postgis/trunk@8950 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis/geometry_estimate.c b/postgis/geometry_estimate.c index 80040914f..41dd64da7 100644 --- a/postgis/geometry_estimate.c +++ b/postgis/geometry_estimate.c @@ -1335,6 +1335,7 @@ Datum geometry_estimated_extent(PG_FUNCTION_ARGS) size_t querysize; GEOM_STATS geomstats; float reltuples; + Datum binval; if ( PG_NARGS() == 3 ) { @@ -1478,7 +1479,7 @@ Datum geometry_estimated_extent(PG_FUNCTION_ARGS) tuple = tuptable->vals[0]; /* Check if the table has zero rows first */ - reltuples = DatumGetFloat4(SPI_getbinval(tuple, tupdesc, 2, &isnull)); + binval = SPI_getbinval(tuple, tupdesc, 2, &isnull); if (isnull) { @@ -1489,6 +1490,7 @@ Datum geometry_estimated_extent(PG_FUNCTION_ARGS) SPI_finish(); PG_RETURN_NULL(); } + reltuples = DatumGetFloat4(binval); if ( ! reltuples ) { POSTGIS_DEBUG(3, "table has estimated zero rows"); @@ -1503,7 +1505,7 @@ Datum geometry_estimated_extent(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - array = DatumGetArrayTypeP(SPI_getbinval(tuple, tupdesc, 1, &isnull)); + binval = SPI_getbinval(tuple, tupdesc, 1, &isnull); if (isnull) { @@ -1514,6 +1516,7 @@ Datum geometry_estimated_extent(PG_FUNCTION_ARGS) SPI_finish(); PG_RETURN_NULL(); } + array = DatumGetArrayTypeP(binval); if ( ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array)) != 4 ) { elog(ERROR, " corrupted histogram");