Bläddra i källkod

do not crash, give out of memory messages

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@42122 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 15 år sedan
förälder
incheckning
dc48b36594
2 ändrade filer med 29 tillägg och 7 borttagningar
  1. 5 1
      vector/v.generalize/matrix.c
  2. 24 6
      vector/v.generalize/smoothing.c

+ 5 - 1
vector/v.generalize/matrix.c

@@ -18,6 +18,8 @@
  ****************************************************************/
 
 #include <string.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
 #include "matrix.h"
 
 int matrix_init(int rows, int cols, MATRIX * res)
@@ -139,8 +141,10 @@ int matrix_inverse(MATRIX a, MATRIX * res, int percents)
     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;

+ 24 - 6
vector/v.generalize/smoothing.c

@@ -405,12 +405,30 @@ int snakes(struct line_pnts *Points, double alpha, double beta, int with_z)
 	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];