[GRASS-SVN] r58990 - in grass/branches/develbranch_6/raster/r.li: r.li.mps r.li.padcv
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Feb 11 06:03:27 PST 2014
Author: neteler
Date: 2014-02-11 06:03:26 -0800 (Tue, 11 Feb 2014)
New Revision: 58990
Modified:
grass/branches/develbranch_6/raster/r.li/r.li.mps/mps.c
grass/branches/develbranch_6/raster/r.li/r.li.padcv/padcv.c
Log:
r.li.mps: avoid double free corruption; trivial white space
Modified: grass/branches/develbranch_6/raster/r.li/r.li.mps/mps.c
===================================================================
--- grass/branches/develbranch_6/raster/r.li/r.li.mps/mps.c 2014-02-11 09:44:37 UTC (rev 58989)
+++ grass/branches/develbranch_6/raster/r.li/r.li.mps/mps.c 2014-02-11 14:03:26 UTC (rev 58990)
@@ -9,14 +9,13 @@
*
*/
-
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
#include <stdlib.h>
#include <fcntl.h>
#include <math.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
#include "../r.li.daemon/defs.h"
#include "../r.li.daemon/avlDefs.h"
#include "../r.li.daemon/avlID.h"
@@ -27,7 +26,6 @@
int calculateD(int fd, struct area_entry *ad, struct Cell_head hd, double *result);
int calculateF(int fd, struct area_entry *ad, struct Cell_head hd, double *result);
-
int main(int argc, char *argv[])
{
struct Option *raster, *conf, *output;
@@ -60,26 +58,17 @@
}
-
int meanPatchSize(int fd, char **par, struct area_entry *ad, double *result)
{
-
char *mapset;
-
int ris = 0;
-
double indice = 0;
-
struct Cell_head hd;
-
-
mapset = G_find_cell(ad->raster, "");
if (G_get_cellhd(ad->raster, mapset, &hd) == -1)
return RLI_ERRORE;
-
-
switch (ad->data_type) {
case CELL_TYPE:
{
@@ -101,14 +90,14 @@
G_fatal_error("data type unknown");
return RLI_ERRORE;
}
+
}
- if (ris != RLI_OK) {
- return RLI_ERRORE;
- }
+ if (ris != RLI_OK)
+ return RLI_ERRORE;
*result = indice;
- return RLI_OK;
+ return RLI_OK;
}
@@ -143,11 +132,8 @@
double EW_DIST1, EW_DIST2, NS_DIST1, NS_DIST2;
avlID_tree albero = NULL;
-
avlID_table *array;
-
-
/* open mask if needed */
if (ad->mask == 1) {
if ((mask_fd = open(ad->mask_name, O_RDONLY, 0755)) < 0)
@@ -479,7 +465,7 @@
G_free(mask_patch_corr);
- G_free(buf_sup);
+ /* G_free(buf_sup); */ /* <-- why not free it? */
return RLI_OK;
}
@@ -488,16 +474,13 @@
{
DCELL *buf;
DCELL *buf_sup;
-
DCELL corrCell;
DCELL precCell;
DCELL supCell;
-
int i, j;
int mask_fd = -1, *mask_buf;
int ris = 0;
int masked = FALSE;
-
long npatch = 0;
long tot = 0;
long zero = 0;
@@ -507,7 +490,6 @@
long doppi = 0;
long *mask_patch_sup;
long *mask_patch_corr;
-
double indice = 0;
double area = 0; /*if all cells are null area=0 */
double areaCorrect = 0;
@@ -1168,7 +1150,6 @@
}
}
-
array = G_malloc(npatch * sizeof(avlID_tableRow));
if (array == NULL) {
G_fatal_error("malloc array failed");
@@ -1213,8 +1194,8 @@
if (masked)
- G_free(mask_buf);
-
+ G_free(mask_buf);
+/* TODO: fix if? */
G_free(mask_patch_corr);
return RLI_OK;
Modified: grass/branches/develbranch_6/raster/r.li/r.li.padcv/padcv.c
===================================================================
--- grass/branches/develbranch_6/raster/r.li/r.li.padcv/padcv.c 2014-02-11 09:44:37 UTC (rev 58989)
+++ grass/branches/develbranch_6/raster/r.li/r.li.padcv/padcv.c 2014-02-11 14:03:26 UTC (rev 58990)
@@ -9,13 +9,13 @@
*
*/
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
#include <stdlib.h>
#include <fcntl.h>
#include <math.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
#include "../r.li.daemon/defs.h"
#include "../r.li.daemon/avlDefs.h"
#include "../r.li.daemon/avlID.h"
@@ -68,35 +68,34 @@
return RLI_ERRORE;
switch (ad->data_type) {
case CELL_TYPE:
-
{
ris = calculate(fd, ad, &indice);
break;
}
case DCELL_TYPE:
-
{
ris = calculateD(fd, ad, &indice);
break;
}
case FCELL_TYPE:
-
{
ris = calculateF(fd, ad, &indice);
break;
}
default:
-
{
G_fatal_error("data type unknown");
return RLI_ERRORE;
}
+
}
if (ris != RLI_OK) {
*result = -1;
return RLI_ERRORE;
}
+
*result = indice;
+
return RLI_OK;
}
@@ -240,24 +239,20 @@
ris = avlID_add(&albero, idCorr, totCorr);
switch (ris) {
case AVL_ERR:
-
{
G_fatal_error("avlID_add error");
return RLI_ERRORE;
}
case AVL_ADD:
-
{
npatch++;
break;
}
case AVL_PRES:
-
{
break;
}
default:
-
{
G_fatal_error
("avlID_add unknown error");
@@ -425,24 +420,20 @@
ris = avlID_add(&albero, idCorr, totCorr);
switch (ris) {
case AVL_ERR:
-
{
G_fatal_error("avlID_add error");
return RLI_ERRORE;
}
case AVL_ADD:
-
{
npatch++;
break;
}
case AVL_PRES:
-
{
break;
}
default:
-
{
G_fatal_error("avlID_add unknown error");
return RLI_ERRORE;
@@ -494,7 +485,7 @@
G_free(mask_patch_sup);
*result = indice;
- G_free(buf_sup);
+ /* G_free(buf_sup); */ /* <-- why not free it? */
return RLI_OK;
}
@@ -637,24 +628,20 @@
ris = avlID_add(&albero, idCorr, totCorr);
switch (ris) {
case AVL_ERR:
-
{
G_fatal_error("avlID_add error");
return RLI_ERRORE;
}
case AVL_ADD:
-
{
npatch++;
break;
}
case AVL_PRES:
-
{
break;
}
default:
-
{
G_fatal_error
("avlID_add unknown error");
@@ -821,24 +808,20 @@
ris = avlID_add(&albero, idCorr, totCorr);
switch (ris) {
case AVL_ERR:
-
{
G_fatal_error("avlID_add error");
return RLI_ERRORE;
}
case AVL_ADD:
-
{
npatch++;
break;
}
case AVL_PRES:
-
{
break;
}
default:
-
{
G_fatal_error("avlID_add unknown error");
return RLI_ERRORE;
@@ -1033,24 +1016,20 @@
ris = avlID_add(&albero, idCorr, totCorr);
switch (ris) {
case AVL_ERR:
-
{
G_fatal_error("avlID_add error");
return RLI_ERRORE;
}
case AVL_ADD:
-
{
npatch++;
break;
}
case AVL_PRES:
-
{
break;
}
default:
-
{
G_fatal_error
("avlID_add unknown error");
@@ -1218,24 +1197,20 @@
ris = avlID_add(&albero, idCorr, totCorr);
switch (ris) {
case AVL_ERR:
-
{
G_fatal_error("avlID_add error");
return RLI_ERRORE;
}
case AVL_ADD:
-
{
npatch++;
break;
}
case AVL_PRES:
-
{
break;
}
default:
-
{
G_fatal_error("avlID_add unknown error");
return RLI_ERRORE;
@@ -1283,8 +1258,10 @@
else
indice = (double)(-1);
if (masked)
- G_free(mask_buf);
+ G_free(mask_buf);
+/* TODO: fix if? */
G_free(mask_patch_sup);
+
*result = indice;
return RLI_OK;
}
More information about the grass-commit
mailing list