瀏覽代碼

Fixed includes so that G_malloc and friends work. Also changed all allocs to use G_malloc and friends (merge from develbranch_6, https://trac.osgeo.org/grass/changeset/37247, https://trac.osgeo.org/grass/changeset/37393)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@37394 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Neteler 16 年之前
父節點
當前提交
dd7c9780a8
共有 1 個文件被更改,包括 13 次插入13 次删除
  1. 13 13
      vector/v.label.sa/labels.c

+ 13 - 13
vector/v.label.sa/labels.c

@@ -60,7 +60,7 @@ label_t *labels_init(struct params *p, int *n_labels)
 
     G_debug(1, "Need to allocate %d bytes of memory",
 	    sizeof(label_t) * label_sz);
-    labels = malloc(sizeof(label_t) * label_sz);
+    labels = (label_t *) G_malloc(sizeof(label_t) * label_sz);
     G_debug(1, "labels=%p", labels);
 
     if (labels == NULL)
@@ -121,7 +121,7 @@ label_t *labels_init(struct params *p, int *n_labels)
 	    label_sz += 100;
 	    G_debug(1, "Need to resize %p to %d bytes of memory",
 		    (void *)labels, sizeof(label_t) * label_sz);
-	    labels = realloc(labels, sizeof(label_t) * label_sz);
+	    labels = G_realloc(labels, sizeof(label_t) * label_sz);
 	    if (labels == NULL) {
 		G_fatal_error(_("Cannot allocate more memory"));
 	    }
@@ -146,14 +146,14 @@ label_t *labels_init(struct params *p, int *n_labels)
 	if (cat < 0)
 	    continue;		/* no cat for this field */
 
-	sql = G_malloc(sql_len);
+	sql = (char *) G_malloc(sql_len);
 	/* Read label from database */
 	sprintf(sql, "select %s from %s where %s = %d", p->column->answer,
 		fi->table, fi->key, cat);
 	G_debug(3, "SQL: %s", sql);
 	db_init_string(&query);
 	db_set_string(&query, sql);
-	free(sql);
+	G_free(sql);
 
 	if (db_open_select_cursor(driver, &query, &cursor, DB_SEQUENTIAL) !=
 	    DB_OK)
@@ -367,7 +367,7 @@ static void label_point_candidates(label_t * label)
     int i;
     label_candidate_t *candidates;
 
-    candidates = calloc(19, sizeof(label_candidate_t));
+    candidates = G_calloc(19, sizeof(label_candidate_t));
     if (candidates == NULL) {
 	G_fatal_error("Cannot allocate memory.");
     }
@@ -510,8 +510,8 @@ static void label_line_candidates(label_t * label)
 
 	return;
     }
-    above_candidates = calloc(n, sizeof(label_candidate_t));
-    below_candidates = calloc(n, sizeof(label_candidate_t));
+    above_candidates = G_calloc(n, sizeof(label_candidate_t));
+    below_candidates = G_calloc(n, sizeof(label_candidate_t));
     if ((above_candidates == NULL) || (below_candidates == NULL)) {
 	G_fatal_error("Cannot allocate memory.");
     }
@@ -721,15 +721,15 @@ static void label_line_candidates(label_t * label)
 	return;
     }
 
-    candidates = calloc(n * 2, sizeof(label_candidate_t));
+    candidates = G_calloc(n * 2, sizeof(label_candidate_t));
     for (i = 0; i < n; i++) {
 	memcpy(&candidates[i * 2], &above_candidates[i],
 	       sizeof(label_candidate_t));
 	memcpy(&candidates[i * 2 + 1], &below_candidates[i],
 	       sizeof(label_candidate_t));
     }
-    free(above_candidates);
-    free(below_candidates);
+    G_free(above_candidates);
+    G_free(below_candidates);
 
     n_c = n * 2;
     /* pick the 32 best candidates */
@@ -743,7 +743,7 @@ static void label_line_candidates(label_t * label)
 	    Vect_destroy_line_struct(candidates[i].swathline);
 	}
 
-	tmp = realloc(candidates, sizeof(label_candidate_t) * 32);
+	tmp = G_realloc(candidates, sizeof(label_candidate_t) * 32);
 	if (tmp != NULL) {
 	    candidates = tmp;
 	}
@@ -1194,7 +1194,7 @@ void label_candidate_overlap(label_t * labels, int n_labels)
 			label_intersection_t *li;
 
 			n = ++(labels[i].candidates[j].n_intersections);
-			li = realloc(labels[i].candidates[j].intersections,
+			li = G_realloc(labels[i].candidates[j].intersections,
 				     n * sizeof(label_intersection_t));
 			if (li == NULL)
 			    G_fatal_error("\nUnable to allocate memory\n");
@@ -1207,7 +1207,7 @@ void label_candidate_overlap(label_t * labels, int n_labels)
 			}
 			labels[i].candidates[j].intersections = li;
 			n = ++(labels[k].candidates[l].n_intersections);
-			li = realloc(labels[k].candidates[l].intersections,
+			li = G_realloc(labels[k].candidates[l].intersections,
 				     n * sizeof(label_intersection_t));
 			if (li == NULL)
 			    G_fatal_error("\nUnable to allocate memory\n");