[GRASS-SVN] r42123 - grass/branches/develbranch_6/vector/v.generalize

svn_grass at osgeo.org svn_grass at osgeo.org
Wed May 5 10:08:55 EDT 2010


Author: mmetz
Date: 2010-05-05 10:08:55 -0400 (Wed, 05 May 2010)
New Revision: 42123

Modified:
   grass/branches/develbranch_6/vector/v.generalize/matrix.c
   grass/branches/develbranch_6/vector/v.generalize/smoothing.c
Log:
do not crash, give out of memory messages, backport from trunk

Modified: grass/branches/develbranch_6/vector/v.generalize/matrix.c
===================================================================
--- grass/branches/develbranch_6/vector/v.generalize/matrix.c	2010-05-05 14:06:29 UTC (rev 42122)
+++ grass/branches/develbranch_6/vector/v.generalize/matrix.c	2010-05-05 14:08:55 UTC (rev 42123)
@@ -17,6 +17,8 @@
  *
  ****************************************************************/
 
+#include <grass/gis.h>
+#include <grass/glocale.h>
 #include "matrix.h"
 
 int matrix_init(int rows, int cols, MATRIX * res)
@@ -138,8 +140,10 @@
     int i, j;
 
     /* initialize output matrix to the identity matrix */
-    if (!matrix_init(a.rows, a.rows, res))
+    if (!matrix_init(a.rows, a.rows, res)) {
+	G_fatal_error(_("Out of memory"));
 	return 0;
+    }
     for (i = 0; i < a.rows; i++) {
 	memset(res->a[i], 0, sizeof(double) * a.cols);
 	res->a[i][i] = 1;

Modified: grass/branches/develbranch_6/vector/v.generalize/smoothing.c
===================================================================
--- grass/branches/develbranch_6/vector/v.generalize/smoothing.c	2010-05-05 14:06:29 UTC (rev 42122)
+++ grass/branches/develbranch_6/vector/v.generalize/smoothing.c	2010-05-05 14:08:55 UTC (rev 42123)
@@ -404,12 +404,30 @@
 	G_fatal_error(_("Out of memory"));
 	return n;
     }
-    matrix_init(n + 2 * plus, 1, &xcoord);
-    matrix_init(n + 2 * plus, 1, &ycoord);
-    matrix_init(n + 2 * plus, 1, &zcoord);
-    matrix_init(n + 2 * plus, 1, &xout);
-    matrix_init(n + 2 * plus, 1, &yout);
-    matrix_init(n + 2 * plus, 1, &zout);
+    if (!matrix_init(n + 2 * plus, 1, &xcoord)) {
+	G_fatal_error(_("Out of memory"));
+	return n;
+    }
+    if (!matrix_init(n + 2 * plus, 1, &ycoord)) {
+	G_fatal_error(_("Out of memory"));
+	return n;
+    }
+    if (!matrix_init(n + 2 * plus, 1, &zcoord)) {
+	G_fatal_error(_("Out of memory"));
+	return n;
+    }
+    if (!matrix_init(n + 2 * plus, 1, &xout)) {
+	G_fatal_error(_("Out of memory"));
+	return n;
+    }
+    if (!matrix_init(n + 2 * plus, 1, &yout)) {
+	G_fatal_error(_("Out of memory"));
+	return n;
+    }
+    if (!matrix_init(n + 2 * plus, 1, &zout)) {
+	G_fatal_error(_("Out of memory"));
+	return n;
+    }
 
     double x0 = Points->x[0];
     double y0 = Points->y[0];



More information about the grass-commit mailing list