[GRASS-SVN] r43618 - grass/branches/releasebranch_6_4/vector/v.generalize

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Sep 22 10:00:36 EDT 2010


Author: neteler
Date: 2010-09-22 14:00:36 +0000 (Wed, 22 Sep 2010)
New Revision: 43618

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

Modified: grass/branches/releasebranch_6_4/vector/v.generalize/matrix.c
===================================================================
--- grass/branches/releasebranch_6_4/vector/v.generalize/matrix.c	2010-09-22 13:59:34 UTC (rev 43617)
+++ grass/branches/releasebranch_6_4/vector/v.generalize/matrix.c	2010-09-22 14:00:36 UTC (rev 43618)
@@ -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/releasebranch_6_4/vector/v.generalize/smoothing.c
===================================================================
--- grass/branches/releasebranch_6_4/vector/v.generalize/smoothing.c	2010-09-22 13:59:34 UTC (rev 43617)
+++ grass/branches/releasebranch_6_4/vector/v.generalize/smoothing.c	2010-09-22 14:00:36 UTC (rev 43618)
@@ -405,12 +405,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