Commit b633449b authored by Bborie Park's avatar Bborie Park

Refactored code and removed the use of SET_VARSIZE for RASTER_band to fix segfault.

Associated ticket is #1044.


git-svn-id: http://svn.osgeo.org/postgis/trunk@7440 b70326c6-7e19-0410-871a-916f4a2858ee
parent 0d115c29
......@@ -2916,7 +2916,7 @@ Datum RASTER_band(PG_FUNCTION_ARGS)
deconstruct_array(array, etype, typlen, typbyval, typalign, &e,
&nulls, &n);
bandNums = (uint32_t *) palloc(sizeof(uint32_t) * n);
bandNums = palloc(sizeof(uint32_t) * n);
for (i = 0, j = 0; i < n; i++) {
if (nulls[i]) continue;
......@@ -2932,10 +2932,9 @@ Datum RASTER_band(PG_FUNCTION_ARGS)
POSTGIS_RT_DEBUGF(3, "band idx (before): %d", idx);
if (idx > pgraster->numBands || idx < 1) {
elog(NOTICE, "Invalid band index (must use 1-based). Returning original raster");
pfree(bandNums);
skip = TRUE;
break;
}
if (skip) break;
bandNums[j] = idx - 1;
POSTGIS_RT_DEBUGF(3, "bandNums[%d] = %d", j, bandNums[j]);
......@@ -2961,15 +2960,14 @@ Datum RASTER_band(PG_FUNCTION_ARGS)
pgrast = rt_raster_serialize(rast);
rt_raster_destroy(rast);
PG_FREE_IF_COPY(pgraster, 0);
}
else {
pgrast = pgraster;
}
if (!pgrast) PG_RETURN_NULL();
if (!pgrast) PG_RETURN_NULL();
SET_VARSIZE(pgrast, pgrast->size);
PG_RETURN_POINTER(pgrast);
SET_VARSIZE(pgrast, pgrast->size);
PG_RETURN_POINTER(pgrast);
}
PG_RETURN_POINTER(pgraster);
}
struct rt_bandstats_t {
......
......@@ -298,3 +298,31 @@ SELECT ST_NumBands(
)
)
);
SELECT ST_NumBands(
ST_Band(
ST_AddBand(
ST_AddBand(
ST_AddBand(
ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0,-1)
, 1, '64BF', 1234.5678, NULL
)
, '64BF', 987.654321, NULL
)
, '64BF', 9876.54321, NULL
)
, ARRAY[1,1,3,999])
);
SELECT ST_NumBands(
ST_Band(
ST_AddBand(
ST_AddBand(
ST_AddBand(
ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0,-1)
, 1, '64BF', 1234.5678, NULL
)
, '64BF', 987.654321, NULL
)
, '64BF', 9876.54321, NULL
)
, ARRAY[999])
);
......@@ -21,3 +21,7 @@
1
1
1
NOTICE: Invalid band index (must use 1-based). Returning original raster
3
NOTICE: Invalid band index (must use 1-based). Returning original raster
3
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment