]> granicus.if.org Git - postgis/commitdiff
Fix raster notices.
authorDarafei Praliaskouski <me@komzpa.net>
Sat, 14 Jul 2018 22:00:33 +0000 (22:00 +0000)
committerDarafei Praliaskouski <me@komzpa.net>
Sat, 14 Jul 2018 22:00:33 +0000 (22:00 +0000)
References #3994
Closes https://github.com/postgis/postgis/pull/271

git-svn-id: http://svn.osgeo.org/postgis/trunk@16645 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_mapalgebra.c
raster/rt_core/rt_raster.c
raster/rt_core/rt_spatial_relationship.c
raster/rt_pg/rtpg_create.c
raster/rt_pg/rtpg_gdal.c
raster/rt_pg/rtpg_geometry.c
raster/rt_pg/rtpg_mapalgebra.c
raster/rt_pg/rtpg_statistics.c
raster/test/cunit/cu_mapalgebra.c

index 7cb7862dd914ed5d4e7d5cdea504bf770871dc0c..4d34520a01ac1b6aa2b9373bc50de47ad8908787 100644 (file)
@@ -1015,7 +1015,7 @@ rt_raster_iterator(
 
                        for (i = 0; i < itrcount; i++) {
                                if (!_param->isempty[i]) {
-                                       memcpy(rtnrast, _param->raster[i], sizeof(struct rt_raster_serialized_t));
+                                       memcpy(rtnrast, _param->raster[i], sizeof(struct rt_raster_t));
                                        break;
                                }
                        }
@@ -1118,11 +1118,11 @@ rt_raster_iterator(
 
                        switch (extenttype) {
                                case ET_CUSTOM:
-                                       memcpy(rtnrast, customextent, sizeof(struct rt_raster_serialized_t));
+                                       memcpy(rtnrast, customextent, sizeof(struct rt_raster_t));
                                        break;
                                /* first, second, last */
                                default:
-                                       memcpy(rtnrast, _param->raster[i], sizeof(struct rt_raster_serialized_t));
+                                       memcpy(rtnrast, _param->raster[i], sizeof(struct rt_raster_t));
                                        break;
                        }
                        rtnrast->numBands = 0;
index 5c42d8125988508ddc741a73e6a08565bea354f5..e468462927d691f4ff05e77c7305e409ee43d046 100644 (file)
@@ -1262,11 +1262,11 @@ rt_raster_compute_skewed_raster(
                        return NULL;
                }
 
-               if (covers)
-                       break;
-
-               raster->width++;
-               raster->height++;
+               if (!covers)
+               {
+                       raster->width++;
+                       raster->height++;
+               }
        }
        while (!covers);
 
@@ -1309,17 +1309,13 @@ rt_raster_compute_skewed_raster(
                                rt_raster_destroy(raster);
                                return NULL;
                        }
+               } while (covers);
 
-                       if (!covers) {
-                               if (i < 1)
-                                       raster->width++;
-                               else
-                                       raster->height++;
+               if (i < 1)
+                       raster->width++;
+               else
+                       raster->height++;
 
-                               break;
-                       }
-               }
-               while (covers);
        }
 
        GEOSGeom_destroy(ngeom);
@@ -1336,7 +1332,7 @@ rt_raster_compute_skewed_raster(
  */
 int
 rt_raster_is_empty(rt_raster raster) {
-       return (NULL == raster || raster->height <= 0 || raster->width <= 0);
+       return (!raster || raster->height == 0 || raster->width == 0);
 }
 
 /**
@@ -2783,7 +2779,7 @@ rt_raster_gdal_rasterize(
                        /* check alignment flag: grid_xw */
                        if (
                                (NULL == ul_xw && NULL == ul_yw) &&
-                               (NULL != grid_xw && NULL != grid_xw) &&
+                               (NULL != grid_xw && NULL != grid_yw) &&
                                FLT_NEQ(*grid_xw, extent.MinX)
                        ) {
                                /* do nothing */
@@ -2798,7 +2794,7 @@ rt_raster_gdal_rasterize(
                        /* check alignment flag: grid_yw */
                        if (
                                (NULL == ul_xw && NULL == ul_yw) &&
-                               (NULL != grid_xw && NULL != grid_xw) &&
+                               (NULL != grid_xw && NULL != grid_yw) &&
                                FLT_NEQ(*grid_yw, extent.MaxY)
                        ) {
                                /* do nothing */
@@ -2815,7 +2811,7 @@ rt_raster_gdal_rasterize(
                        /* check alignment flag: grid_xw */
                        if (
                                (NULL == ul_xw && NULL == ul_yw) &&
-                               (NULL != grid_xw && NULL != grid_xw) &&
+                               (NULL != grid_xw && NULL != grid_yw) &&
                                FLT_NEQ(*grid_xw, extent.MinX)
                        ) {
                                /* do nothing */
@@ -2831,7 +2827,7 @@ rt_raster_gdal_rasterize(
                        /* check alignment flag: grid_yw */
                        if (
                                (NULL == ul_xw && NULL == ul_yw) &&
-                               (NULL != grid_xw && NULL != grid_xw) &&
+                               (NULL != grid_xw && NULL != grid_yw) &&
                                FLT_NEQ(*grid_yw, extent.MaxY)
                        ) {
                                /* do nothing */
index eb971c38d2a6b0c0c0976ed83ecbb2f3b12373de..60db67349bf6918bf770f3bfe930298b0b7ee0c6 100644 (file)
@@ -995,7 +995,6 @@ rt_raster_intersects(
        int *intersects
 ) {
        int i;
-       int j;
        int within = 0;
 
        LWGEOM *hull[2] = {NULL};
@@ -1069,27 +1068,28 @@ rt_raster_intersects(
                initGEOS(rtinfo, lwgeom_geos_error);
 
                rtn = 1;
-               for (i = 0; i < 2; i++) {
-                       if ((rt_raster_get_convex_hull(i < 1 ? rast1 : rast2, &(hull[i])) != ES_NONE) || NULL == hull[i]) {
-                               for (j = 0; j < i; j++) {
-                                       GEOSGeom_destroy(ghull[j]);
-                                       lwgeom_free(hull[j]);
-                               }
-                               rtn = 0;
-                               break;
-                       }
-                       ghull[i] = (GEOSGeometry *) LWGEOM2GEOS(hull[i], 0);
-                       if (NULL == ghull[i]) {
-                               for (j = 0; j < i; j++) {
-                                       GEOSGeom_destroy(ghull[j]);
-                                       lwgeom_free(hull[j]);
-                               }
-                               lwgeom_free(hull[i]);
-                               rtn = 0;
-                               break;
-                       }
+
+               if ((rt_raster_get_convex_hull(rast1, &(hull[0])) != ES_NONE) || !hull[0]) {
+                       break;
+               }
+               ghull[0] = (GEOSGeometry *) LWGEOM2GEOS(hull[0], 0);
+               if (!ghull[0]) {
+                       lwgeom_free(hull[0]);
+                       break;
+               }
+
+               if ((rt_raster_get_convex_hull(rast2, &(hull[1])) != ES_NONE) || !hull[1]) {
+                       GEOSGeom_destroy(ghull[0]);
+                       lwgeom_free(hull[0]);
+                       break;
+               }
+               ghull[1] = (GEOSGeometry *) LWGEOM2GEOS(hull[1], 0);
+               if (!ghull[0]) {
+                       GEOSGeom_destroy(ghull[0]);
+                       lwgeom_free(hull[1]);
+                       lwgeom_free(hull[0]);
+                       break;
                }
-               if (!rtn) break;
 
                /* test to see if raster within the other */
                within = 0;
index f8bedc3c5a8e53e9a5957624b220ecc56fa9a3a5..7dceed40db0a6c406849eec806fae4c52dd302e7 100644 (file)
@@ -1312,7 +1312,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
                                int nband = arg2->nbands[i] + 1;
                                rt_raster_destroy(tile);
                                rt_raster_destroy(arg2->raster.raster);
-                               if (arg2->numbands) pfree(arg2->nbands);
+                               pfree(arg2->nbands);
                                pfree(arg2);
                                elog(ERROR, "RASTER_tile: Could not get band %d from source raster", nband);
                                SRF_RETURN_DONE(funcctx);
@@ -1343,7 +1343,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
                                if (band == NULL) {
                                        rt_raster_destroy(tile);
                                        rt_raster_destroy(arg2->raster.raster);
-                                       if (arg2->numbands) pfree(arg2->nbands);
+                                       pfree(arg2->nbands);
                                        pfree(arg2);
                                        elog(ERROR, "RASTER_tile: Could not get newly added band from output tile");
                                        SRF_RETURN_DONE(funcctx);
@@ -1368,7 +1368,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
                                        if (rt_band_get_pixel_line(_band, rx, k, len, &vals, &nvals) != ES_NONE) {
                                                rt_raster_destroy(tile);
                                                rt_raster_destroy(arg2->raster.raster);
-                                               if (arg2->numbands) pfree(arg2->nbands);
+                                               pfree(arg2->nbands);
                                                pfree(arg2);
                                                elog(ERROR, "RASTER_tile: Could not get pixel line from source raster");
                                                SRF_RETURN_DONE(funcctx);
@@ -1377,7 +1377,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
                                        if (nvals && rt_band_set_pixel_line(band, 0, j, vals, nvals) != ES_NONE) {
                                                rt_raster_destroy(tile);
                                                rt_raster_destroy(arg2->raster.raster);
-                                               if (arg2->numbands) pfree(arg2->nbands);
+                                               pfree(arg2->nbands);
                                                pfree(arg2);
                                                elog(ERROR, "RASTER_tile: Could not set pixel line of output tile");
                                                SRF_RETURN_DONE(funcctx);
@@ -1399,7 +1399,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
                                if (band == NULL) {
                                        rt_raster_destroy(tile);
                                        rt_raster_destroy(arg2->raster.raster);
-                                       if (arg2->numbands) pfree(arg2->nbands);
+                                       pfree(arg2->nbands);
                                        pfree(arg2);
                                        elog(ERROR, "RASTER_tile: Could not create new offline band for output tile");
                                        SRF_RETURN_DONE(funcctx);
@@ -1409,7 +1409,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
                                        rt_band_destroy(band);
                                        rt_raster_destroy(tile);
                                        rt_raster_destroy(arg2->raster.raster);
-                                       if (arg2->numbands) pfree(arg2->nbands);
+                                       pfree(arg2->nbands);
                                        pfree(arg2);
                                        elog(ERROR, "RASTER_tile: Could not add new offline band to output tile");
                                        SRF_RETURN_DONE(funcctx);
@@ -1482,9 +1482,7 @@ Datum RASTER_band(PG_FUNCTION_ARGS)
                elog(NOTICE, "Band number(s) not provided.  Returning original raster");
                skip = TRUE;
        }
-       do {
-               if (skip) break;
-
+       if (!skip) {
                numBands = rt_raster_get_num_bands(raster);
 
                array = PG_GETARG_ARRAYTYPE_P(1);
@@ -1521,7 +1519,7 @@ Datum RASTER_band(PG_FUNCTION_ARGS)
 
                        POSTGIS_RT_DEBUGF(3, "band idx (before): %d", idx);
                        if (idx > numBands || idx < 1) {
-        elog(NOTICE, "Invalid band index (must use 1-based). Returning original raster");
+                       elog(NOTICE, "Invalid band index (must use 1-based). Returning original raster");
                                skip = TRUE;
                                break;
                        }
@@ -1536,7 +1534,6 @@ Datum RASTER_band(PG_FUNCTION_ARGS)
                        skip = TRUE;
                }
        }
-       while (0);
 
        if (!skip) {
                rast = rt_raster_from_band(raster, bandNums, j);
index aaaa80a03360c8b71fe98480d699887963b648ab..dd3a8ff3e2315a363a6599ac2457fcd396ac20ce 100644 (file)
@@ -250,7 +250,7 @@ Datum RASTER_asGDALRaster(PG_FUNCTION_ARGS)
 
                                if (strlen(option)) {
                                        options[j] = (char *) palloc(sizeof(char) * (strlen(option) + 1));
-                                       options[j] = option;
+                                       strcpy(options[j], option);
                                        j++;
                                }
                        }
@@ -323,15 +323,8 @@ Datum RASTER_asGDALRaster(PG_FUNCTION_ARGS)
        SET_VARSIZE(result, result_size);
        memcpy(VARDATA(result), gdal, VARSIZE(result) - VARHDRSZ);
 
-       /* for test output
-       FILE *fh = NULL;
-       fh = fopen("/tmp/out.dat", "w");
-       fwrite(gdal, sizeof(uint8_t), gdal_size, fh);
-       fclose(fh);
-       */
-
        /* free gdal mem buffer */
-       if (gdal) CPLFree(gdal);
+       CPLFree(gdal);
 
        POSTGIS_RT_DEBUG(3, "RASTER_asGDALRaster: Returning pointer to GDAL raster");
        PG_RETURN_POINTER(result);
@@ -649,7 +642,7 @@ Datum RASTER_GDALWarp(PG_FUNCTION_ARGS)
 
                dst_srs = rtpg_getSR(dst_srid);
                if (NULL == dst_srs) {
-                       if (!no_srid) pfree(src_srs);
+                       pfree(src_srs);
                        rt_raster_destroy(raster);
                        PG_FREE_IF_COPY(pgraster, 0);
                        elog(ERROR, "RASTER_GDALWarp: Target SRID (%d) is unknown", dst_srid);
index df2b7691eb84ac93a798e3d24d8fae3df54371f5..ea58f0003c395d3df4a61617e53c0deedcac1c92 100644 (file)
@@ -1199,7 +1199,7 @@ Datum RASTER_asRaster(PG_FUNCTION_ARGS)
 
        /* all touched */
        if (!PG_ARGISNULL(14) && PG_GETARG_BOOL(14) == TRUE) {
-               if (options_len < 1) {
+               if (options_len == 0) {
                        options_len = 1;
                        options = (char **) palloc(sizeof(char *) * options_len);
                }
@@ -1209,7 +1209,7 @@ Datum RASTER_asRaster(PG_FUNCTION_ARGS)
                }
 
                options[options_len - 1] = palloc(sizeof(char*) * (strlen("ALL_TOUCHED=TRUE") + 1));
-               options[options_len - 1] = "ALL_TOUCHED=TRUE";
+               strcpy(options[options_len - 1], "ALL_TOUCHED=TRUE");
        }
 
        if (options_len) {
index 4984f3eb1c37da513c1071139fd2972eb411e265..f19491a2396b0703844f92c127f12fd301a910dd 100644 (file)
@@ -1050,7 +1050,7 @@ static int rtpg_nmapalgebraexpr_callback(
        rtpg_nmapalgebraexpr_callback_arg *callback = (rtpg_nmapalgebraexpr_callback_arg *) userarg;
        SPIPlanPtr plan = NULL;
        int i = 0;
-       int id = -1;
+       uint8_t id = 0;
 
        if (arg == NULL)
                return 0;
@@ -4715,8 +4715,7 @@ Datum RASTER_mapAlgebraExpr(PG_FUNCTION_ARGS)
         POSTGIS_RT_DEBUGF(4, "RASTER_mapAlgebraExpr: New raster now has %d bands",
                 rt_raster_get_num_bands(newrast));
 
-        if (initexpr)
-            pfree(initexpr);
+        pfree(initexpr);
         rt_raster_destroy(raster);
         PG_FREE_IF_COPY(pgraster, 0);
 
@@ -7004,13 +7003,13 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS)
                                                else if (spi_plan[i] != NULL) {
                                                        POSTGIS_RT_DEBUGF(4, "Using prepared plan: %d", i);
 
+                                                       /* reset values to (Datum) NULL */
+                                                       memset(values, (Datum) NULL, sizeof(Datum) * argkwcount);
+                                                       /* reset nulls to FALSE */
+                                                       memset(nulls, FALSE, sizeof(char) * argkwcount);
+
                                                        /* expression has argument(s) */
                                                        if (spi_argcount[i]) {
-                                                               /* reset values to (Datum) NULL */
-                                                               memset(values, (Datum) NULL, sizeof(Datum) * argkwcount);
-                                                               /* reset nulls to FALSE */
-                                                               memset(nulls, FALSE, sizeof(char) * argkwcount);
-
                                                                /* set values and nulls */
                                                                for (j = 0; j < argkwcount; j++) {
                                                                        idx = argpos[i][j];
index c74ab4b6a8de6468f78aa0550cefb26e48c79074..290ba4bc09baba4f5b5c221492734ca6247b5903 100644 (file)
@@ -309,13 +309,11 @@ Datum RASTER_summaryStatsCoverage(PG_FUNCTION_ARGS)
        SPI_cursor_fetch(portal, TRUE, 1);
        while (SPI_processed == 1 && SPI_tuptable != NULL) {
                tupdesc = SPI_tuptable->tupdesc;
-               tuptable = SPI_tuptable;
-               tuple = tuptable->vals[0];
+               tuple = SPI_tuptable->vals[0];
 
                datum = SPI_getbinval(tuple, tupdesc, 1, &isNull);
                if (SPI_result == SPI_ERROR_NOATTRIBUTE) {
-
-                       if (SPI_tuptable) SPI_freetuptable(tuptable);
+                       SPI_freetuptable(SPI_tuptable);
                        SPI_cursor_close(portal);
                        SPI_finish();
 
@@ -332,8 +330,7 @@ Datum RASTER_summaryStatsCoverage(PG_FUNCTION_ARGS)
 
                raster = rt_raster_deserialize(pgraster, FALSE);
                if (!raster) {
-
-                       if (SPI_tuptable) SPI_freetuptable(tuptable);
+                       SPI_freetuptable(SPI_tuptable);
                        SPI_cursor_close(portal);
                        SPI_finish();
 
@@ -349,7 +346,7 @@ Datum RASTER_summaryStatsCoverage(PG_FUNCTION_ARGS)
 
                        rt_raster_destroy(raster);
 
-                       if (SPI_tuptable) SPI_freetuptable(tuptable);
+                       SPI_freetuptable(SPI_tuptable);
                        SPI_cursor_close(portal);
                        SPI_finish();
 
@@ -364,7 +361,7 @@ Datum RASTER_summaryStatsCoverage(PG_FUNCTION_ARGS)
 
                        rt_raster_destroy(raster);
 
-                       if (SPI_tuptable) SPI_freetuptable(tuptable);
+                       SPI_freetuptable(SPI_tuptable);
                        SPI_cursor_close(portal);
                        SPI_finish();
 
@@ -381,7 +378,7 @@ Datum RASTER_summaryStatsCoverage(PG_FUNCTION_ARGS)
                if (NULL == stats) {
                        elog(NOTICE, "Cannot compute summary statistics for band at index %d. Returning NULL", bandindex);
 
-                       if (SPI_tuptable) SPI_freetuptable(tuptable);
+                       SPI_freetuptable(SPI_tuptable);
                        SPI_cursor_close(portal);
                        SPI_finish();
 
@@ -394,8 +391,7 @@ Datum RASTER_summaryStatsCoverage(PG_FUNCTION_ARGS)
                        if (NULL == rtn) {
                                rtn = (rt_bandstats) SPI_palloc(sizeof(struct rt_bandstats_t));
                                if (NULL == rtn) {
-
-                                       if (SPI_tuptable) SPI_freetuptable(tuptable);
+                                       SPI_freetuptable(SPI_tuptable);
                                        SPI_cursor_close(portal);
                                        SPI_finish();
 
@@ -431,7 +427,7 @@ Datum RASTER_summaryStatsCoverage(PG_FUNCTION_ARGS)
                SPI_cursor_fetch(portal, TRUE, 1);
        }
 
-       if (SPI_tuptable) SPI_freetuptable(tuptable);
+       if (SPI_tuptable) SPI_freetuptable(SPI_tuptable);
        SPI_cursor_close(portal);
        SPI_finish();
 
@@ -1229,7 +1225,6 @@ Datum RASTER_histogramCoverage(PG_FUNCTION_ARGS)
                double max = 0;
                int spi_result;
                Portal portal;
-               SPITupleTable *tuptable = NULL;
                HeapTuple tuple;
                Datum datum;
                bool isNull = FALSE;
@@ -1391,7 +1386,7 @@ Datum RASTER_histogramCoverage(PG_FUNCTION_ARGS)
                sql = (char *) palloc(len);
                if (NULL == sql) {
 
-                       if (SPI_tuptable) SPI_freetuptable(tuptable);
+                       if (SPI_tuptable) SPI_freetuptable(SPI_tuptable);
                        SPI_finish();
 
                        if (bin_width_count) pfree(bin_width);
@@ -1408,7 +1403,7 @@ Datum RASTER_histogramCoverage(PG_FUNCTION_ARGS)
                pfree(sql);
                if (spi_result != SPI_OK_SELECT || SPI_tuptable == NULL || SPI_processed != 1) {
 
-                       if (SPI_tuptable) SPI_freetuptable(tuptable);
+                       if (SPI_tuptable) SPI_freetuptable(SPI_tuptable);
                        SPI_finish();
 
                        if (bin_width_count) pfree(bin_width);
@@ -1419,13 +1414,12 @@ Datum RASTER_histogramCoverage(PG_FUNCTION_ARGS)
                }
 
                tupdesc = SPI_tuptable->tupdesc;
-               tuptable = SPI_tuptable;
-               tuple = tuptable->vals[0];
+               tuple = SPI_tuptable->vals[0];
 
                tmp = SPI_getvalue(tuple, tupdesc, 1);
                if (NULL == tmp || !strlen(tmp)) {
 
-                       if (SPI_tuptable) SPI_freetuptable(tuptable);
+                       SPI_freetuptable(SPI_tuptable);
                        SPI_finish();
 
                        if (bin_width_count) pfree(bin_width);
@@ -1441,7 +1435,7 @@ Datum RASTER_histogramCoverage(PG_FUNCTION_ARGS)
                tmp = SPI_getvalue(tuple, tupdesc, 2);
                if (NULL == tmp || !strlen(tmp)) {
 
-                       if (SPI_tuptable) SPI_freetuptable(tuptable);
+                       if (SPI_tuptable) SPI_freetuptable(SPI_tuptable);
                        SPI_finish();
 
                        if (bin_width_count) pfree(bin_width);
@@ -1460,7 +1454,7 @@ Datum RASTER_histogramCoverage(PG_FUNCTION_ARGS)
                sql = (char *) palloc(len);
                if (NULL == sql) {
 
-                       if (SPI_tuptable) SPI_freetuptable(tuptable);
+                       if (SPI_tuptable) SPI_freetuptable(SPI_tuptable);
                        SPI_finish();
 
                        if (bin_width_count) pfree(bin_width);
@@ -1486,13 +1480,11 @@ Datum RASTER_histogramCoverage(PG_FUNCTION_ARGS)
                SPI_cursor_fetch(portal, TRUE, 1);
                while (SPI_processed == 1 && SPI_tuptable != NULL) {
                        tupdesc = SPI_tuptable->tupdesc;
-                       tuptable = SPI_tuptable;
-                       tuple = tuptable->vals[0];
+                       tuple = SPI_tuptable->vals[0];
 
                        datum = SPI_getbinval(tuple, tupdesc, 1, &isNull);
                        if (SPI_result == SPI_ERROR_NOATTRIBUTE) {
-
-                               if (SPI_tuptable) SPI_freetuptable(tuptable);
+                               SPI_freetuptable(SPI_tuptable);
                                SPI_cursor_close(portal);
                                SPI_finish();
 
@@ -1513,7 +1505,7 @@ Datum RASTER_histogramCoverage(PG_FUNCTION_ARGS)
                        raster = rt_raster_deserialize(pgraster, FALSE);
                        if (!raster) {
 
-                               if (SPI_tuptable) SPI_freetuptable(tuptable);
+                               if (SPI_tuptable) SPI_freetuptable(SPI_tuptable);
                                SPI_cursor_close(portal);
                                SPI_finish();
 
@@ -1532,7 +1524,7 @@ Datum RASTER_histogramCoverage(PG_FUNCTION_ARGS)
 
                                rt_raster_destroy(raster);
 
-                               if (SPI_tuptable) SPI_freetuptable(tuptable);
+                               if (SPI_tuptable) SPI_freetuptable(SPI_tuptable);
                                SPI_cursor_close(portal);
                                SPI_finish();
 
@@ -1550,7 +1542,7 @@ Datum RASTER_histogramCoverage(PG_FUNCTION_ARGS)
 
                                rt_raster_destroy(raster);
 
-                               if (SPI_tuptable) SPI_freetuptable(tuptable);
+                               if (SPI_tuptable) SPI_freetuptable(SPI_tuptable);
                                SPI_cursor_close(portal);
                                SPI_finish();
 
@@ -1570,7 +1562,7 @@ Datum RASTER_histogramCoverage(PG_FUNCTION_ARGS)
                        if (NULL == stats) {
                                elog(NOTICE, "Cannot compute summary statistics for band at index %d. Returning NULL", bandindex);
 
-                               if (SPI_tuptable) SPI_freetuptable(tuptable);
+                               if (SPI_tuptable) SPI_freetuptable(SPI_tuptable);
                                SPI_cursor_close(portal);
                                SPI_finish();
 
@@ -1588,7 +1580,7 @@ Datum RASTER_histogramCoverage(PG_FUNCTION_ARGS)
                                if (NULL == hist || !count) {
                                        elog(NOTICE, "Cannot compute histogram for band at index %d", bandindex);
 
-                                       if (SPI_tuptable) SPI_freetuptable(tuptable);
+                                       if (SPI_tuptable) SPI_freetuptable(SPI_tuptable);
                                        SPI_cursor_close(portal);
                                        SPI_finish();
 
@@ -1607,7 +1599,7 @@ Datum RASTER_histogramCoverage(PG_FUNCTION_ARGS)
                                        if (NULL == covhist) {
 
                                                pfree(hist);
-                                               if (SPI_tuptable) SPI_freetuptable(tuptable);
+                                               if (SPI_tuptable) SPI_freetuptable(SPI_tuptable);
                                                SPI_cursor_close(portal);
                                                SPI_finish();
 
@@ -1643,7 +1635,7 @@ Datum RASTER_histogramCoverage(PG_FUNCTION_ARGS)
                        SPI_cursor_fetch(portal, TRUE, 1);
                }
 
-               if (SPI_tuptable) SPI_freetuptable(tuptable);
+               if (SPI_tuptable) SPI_freetuptable(SPI_tuptable);
                SPI_cursor_close(portal);
                SPI_finish();
 
@@ -2228,13 +2220,11 @@ Datum RASTER_quantileCoverage(PG_FUNCTION_ARGS)
                        if (NULL != covquant) pfree(covquant);
 
                        tupdesc = SPI_tuptable->tupdesc;
-                       tuptable = SPI_tuptable;
-                       tuple = tuptable->vals[0];
+                       tuple = SPI_tuptable->vals[0];
 
                        datum = SPI_getbinval(tuple, tupdesc, 1, &isNull);
                        if (SPI_result == SPI_ERROR_NOATTRIBUTE) {
-
-                               if (SPI_tuptable) SPI_freetuptable(tuptable);
+                               SPI_freetuptable(SPI_tuptable);
                                SPI_cursor_close(portal);
                                SPI_finish();
 
@@ -2252,7 +2242,7 @@ Datum RASTER_quantileCoverage(PG_FUNCTION_ARGS)
                        raster = rt_raster_deserialize(pgraster, FALSE);
                        if (!raster) {
 
-                               if (SPI_tuptable) SPI_freetuptable(tuptable);
+                               SPI_freetuptable(SPI_tuptable);
                                SPI_cursor_close(portal);
                                SPI_finish();
 
@@ -2268,7 +2258,7 @@ Datum RASTER_quantileCoverage(PG_FUNCTION_ARGS)
 
                                rt_raster_destroy(raster);
 
-                               if (SPI_tuptable) SPI_freetuptable(tuptable);
+                               SPI_freetuptable(SPI_tuptable);
                                SPI_cursor_close(portal);
                                SPI_finish();
 
@@ -2283,7 +2273,7 @@ Datum RASTER_quantileCoverage(PG_FUNCTION_ARGS)
 
                                rt_raster_destroy(raster);
 
-                               if (SPI_tuptable) SPI_freetuptable(tuptable);
+                               SPI_freetuptable(SPI_tuptable);
                                SPI_cursor_close(portal);
                                SPI_finish();
 
@@ -2302,10 +2292,10 @@ Datum RASTER_quantileCoverage(PG_FUNCTION_ARGS)
                        rt_band_destroy(band);
                        rt_raster_destroy(raster);
 
-                       if (NULL == covquant || !count) {
+                       if (!covquant || !count) {
                                elog(NOTICE, "Cannot compute quantiles for band at index %d", bandindex);
 
-                               if (SPI_tuptable) SPI_freetuptable(tuptable);
+                               SPI_freetuptable(SPI_tuptable);
                                SPI_cursor_close(portal);
                                SPI_finish();
 
@@ -2325,10 +2315,10 @@ Datum RASTER_quantileCoverage(PG_FUNCTION_ARGS)
                                covquant2[i].value = covquant[i].value;
                }
 
-               if (NULL != covquant) pfree(covquant);
+               pfree(covquant);
                quantile_llist_destroy(&qlls, qlls_count);
 
-               if (SPI_tuptable) SPI_freetuptable(tuptable);
+               if (SPI_tuptable) SPI_freetuptable(SPI_tuptable);
                SPI_cursor_close(portal);
                SPI_finish();
 
@@ -2646,7 +2636,6 @@ Datum RASTER_valueCountCoverage(PG_FUNCTION_ARGS) {
                char *sql = NULL;
                int spi_result;
                Portal portal;
-               SPITupleTable *tuptable = NULL;
                HeapTuple tuple;
                Datum datum;
                bool isNull = FALSE;
@@ -2781,7 +2770,7 @@ Datum RASTER_valueCountCoverage(PG_FUNCTION_ARGS) {
                sql = (char *) palloc(len);
                if (NULL == sql) {
 
-                       if (SPI_tuptable) SPI_freetuptable(tuptable);
+                       if (SPI_tuptable) SPI_freetuptable(SPI_tuptable);
                        SPI_finish();
 
                        if (search_values_count) pfree(search_values);
@@ -2807,13 +2796,12 @@ Datum RASTER_valueCountCoverage(PG_FUNCTION_ARGS) {
                SPI_cursor_fetch(portal, TRUE, 1);
                while (SPI_processed == 1 && SPI_tuptable != NULL) {
                        tupdesc = SPI_tuptable->tupdesc;
-                       tuptable = SPI_tuptable;
-                       tuple = tuptable->vals[0];
+                       tuple = SPI_tuptable->vals[0];
 
                        datum = SPI_getbinval(tuple, tupdesc, 1, &isNull);
                        if (SPI_result == SPI_ERROR_NOATTRIBUTE) {
 
-                               if (SPI_tuptable) SPI_freetuptable(tuptable);
+                               SPI_freetuptable(SPI_tuptable);
                                SPI_cursor_close(portal);
                                SPI_finish();
 
@@ -2834,7 +2822,7 @@ Datum RASTER_valueCountCoverage(PG_FUNCTION_ARGS) {
                        raster = rt_raster_deserialize(pgraster, FALSE);
                        if (!raster) {
 
-                               if (SPI_tuptable) SPI_freetuptable(tuptable);
+                               SPI_freetuptable(SPI_tuptable);
                                SPI_cursor_close(portal);
                                SPI_finish();
 
@@ -2853,7 +2841,7 @@ Datum RASTER_valueCountCoverage(PG_FUNCTION_ARGS) {
 
                                rt_raster_destroy(raster);
 
-                               if (SPI_tuptable) SPI_freetuptable(tuptable);
+                               SPI_freetuptable(SPI_tuptable);
                                SPI_cursor_close(portal);
                                SPI_finish();
 
@@ -2871,7 +2859,7 @@ Datum RASTER_valueCountCoverage(PG_FUNCTION_ARGS) {
 
                                rt_raster_destroy(raster);
 
-                               if (SPI_tuptable) SPI_freetuptable(tuptable);
+                               SPI_freetuptable(SPI_tuptable);
                                SPI_cursor_close(portal);
                                SPI_finish();
 
@@ -2889,7 +2877,7 @@ Datum RASTER_valueCountCoverage(PG_FUNCTION_ARGS) {
                        if (NULL == vcnts || !count) {
                                elog(NOTICE, "Cannot count the values for band at index %d", bandindex);
 
-                               if (SPI_tuptable) SPI_freetuptable(tuptable);
+                               SPI_freetuptable(SPI_tuptable);
                                SPI_cursor_close(portal);
                                SPI_finish();
 
@@ -2906,7 +2894,7 @@ Datum RASTER_valueCountCoverage(PG_FUNCTION_ARGS) {
                                covvcnts = (rt_valuecount) SPI_palloc(sizeof(struct rt_valuecount_t) * count);
                                if (NULL == covvcnts) {
 
-                                       if (SPI_tuptable) SPI_freetuptable(tuptable);
+                                       SPI_freetuptable(SPI_tuptable);
                                        SPI_cursor_close(portal);
                                        SPI_finish();
 
@@ -2942,14 +2930,12 @@ Datum RASTER_valueCountCoverage(PG_FUNCTION_ARGS) {
                                        else {
                                                covcount++;
                                                covvcnts = SPI_repalloc(covvcnts, sizeof(struct rt_valuecount_t) * covcount);
-                                               if (NULL == covvcnts) {
-
-                                                       if (SPI_tuptable) SPI_freetuptable(tuptable);
+                                               if (!covvcnts) {
+                                                       SPI_freetuptable(SPI_tuptable);
                                                        SPI_cursor_close(portal);
                                                        SPI_finish();
 
                                                        if (search_values_count) pfree(search_values);
-                                                       if (NULL != covvcnts) free(covvcnts);
 
                                                        MemoryContextSwitchTo(oldcontext);
                                                        elog(ERROR, "RASTER_valueCountCoverage: Cannot change allocated memory for value counts of coverage");
@@ -2971,7 +2957,7 @@ Datum RASTER_valueCountCoverage(PG_FUNCTION_ARGS) {
                        SPI_cursor_fetch(portal, TRUE, 1);
                }
 
-               if (SPI_tuptable) SPI_freetuptable(tuptable);
+               if (SPI_tuptable) SPI_freetuptable(SPI_tuptable);
                SPI_cursor_close(portal);
                SPI_finish();
 
index b50927bb2eacb245b586c6a0c7e1bc660ed6d2ff..32e9e6e04db51b5c99e1b1fc76f9fbeb27715e02 100644 (file)
@@ -240,8 +240,8 @@ static int testRasterIterator3_callback(rt_iterator_arg arg, void *userarg, doub
        }
        /* 0,2 */
        else if (
-               arg->dst_pixel[0] == 3 &&
-               arg->dst_pixel[1] == 3
+               arg->dst_pixel[0] == 0 &&
+               arg->dst_pixel[1] == 2
        ) {
                CU_ASSERT_DOUBLE_EQUAL(arg->values[0][0][0], 16, DBL_EPSILON);
                CU_ASSERT_EQUAL(arg->nodata[0][0][0], 0);