]> mj.ucw.cz Git - leo.git/commitdiff
Labeller: use xmalloc instead of malloc
authorKarryanna <karry@karryanna.cz>
Mon, 29 Jun 2015 15:00:29 +0000 (17:00 +0200)
committerKarryanna <karry@karryanna.cz>
Mon, 29 Jun 2015 15:00:29 +0000 (17:00 +0200)
labeller.c

index 80d69e8f1bdf755a7c8108f476b38c1f43cf1d0e..f9eb4a839fbec90b131b309839c2e0e54b2cb82c 100644 (file)
@@ -269,14 +269,14 @@ void make_bitmap_icon(struct variant *v, struct sym_icon *si)
 {
   v->width = si->sir.width + 1;
   v->height = si->sir.height + 1;
-  v->bitmap = malloc(v->width * v->height * sizeof(bool));
+  v->bitmap = xmalloc(v->width * v->height * sizeof(bool));
   for (int i=0; i<v->width*v->height; i++) v->bitmap[i] = 1;
 }
 
 void make_bitmap_point(struct variant *v, struct sym_point *sp)
 {
   v->width = v->height = sp->size + 1;
-  v->bitmap = malloc(v->width * v->height * sizeof(bool));
+  v->bitmap = xmalloc(v->width * v->height * sizeof(bool));
   // FIXME: Okay, memset would be much nicer here
   for (int i=0; i<sp->size*sp->size; i++) v->bitmap[i] = 1;
 }
@@ -310,7 +310,7 @@ void make_bitmap_label(struct variant *v, struct sym_text *text)
 
   v->width = max_x - min_x + 1;
   v->height = max_y - min_y + 1;
-  v->bitmap = malloc(v->width * v->height * sizeof(bool));
+  v->bitmap = xmalloc(v->width * v->height * sizeof(bool));
   memset(v->bitmap, 0, v->width * v->height * sizeof(bool));
 
   for (int i=0; i<th; i++)
@@ -761,14 +761,14 @@ void cut_edge(struct graph_edge *e, double dist)
   if (dbg_segments >= VERBOSITY_PLACEMENT)
     printf("Cutting [%.2f; %.2f] -- [%.2f; %.2f] to dist %.2f\n", e->n1->o->x, e->n1->o->y, e->n2->o->x, e->n2->o->y, dist);
 
-  struct graph_edge *new = malloc(sizeof(struct graph_edge));
+  struct graph_edge *new = xmalloc(sizeof(struct graph_edge));
   *new = *e;
   e->next = new;
 
   switch (e->label->type)
   {
     case SYMBOLIZER_TEXT:
-      new->label = malloc(sizeof(struct sym_text));
+      new->label = xmalloc(sizeof(struct sym_text));
       *((struct sym_text *) new->label) = *((struct sym_text *) e->label);
       break;
     default:
@@ -786,8 +786,8 @@ void cut_edge(struct graph_edge *e, double dist)
     return;
   }
 
-  struct osm_node *n11 = malloc(sizeof(struct osm_node));
-  struct graph_node *gn = malloc(sizeof(struct graph_node));
+  struct osm_node *n11 = xmalloc(sizeof(struct osm_node));
+  struct graph_node *gn = xmalloc(sizeof(struct graph_node));
   gn->o = n11;
   double vsize = sqrt(pow(n1->x - n2->x, 2) + pow(n1->y - n2->y, 2));
   n11->x = n1->x + (n2->x - n1->x) / vsize * dist;
@@ -861,7 +861,7 @@ void make_segments(void)
       }
 
       rs = make_new_segment(rls, NULL);
-      rs->label = malloc(sizeof(struct sym_text));
+      rs->label = xmalloc(sizeof(struct sym_text));
       *((struct sym_text *) rs->label) = *((struct sym_text *) e->label);
 
       rs->x1 = e->n1->o->x;
@@ -936,7 +936,7 @@ void dump_linelabel_requests(void)
 
 void dump_bitmaps(struct individual *individual)
 {
-  bool *bitmap = malloc(page_width_int * page_height_int * sizeof(bool));
+  bool *bitmap = xmalloc(page_width_int * page_height_int * sizeof(bool));
   printf("Bitmap size is %d\n", page_width_int * page_height_int);
   for (int i=0; i<page_height_int; i++)
     for (int j=0; j<page_width_int; j++)
@@ -1305,7 +1305,7 @@ void breed(void)
 
 struct individual **perform_crossover(struct individual *parent1, struct individual *parent2)
 {
-  struct individual **buffer = malloc(2*sizeof(struct individual));
+  struct individual **buffer = xmalloc(2*sizeof(struct individual));
   struct individual *child1 = ep_alloc(ep_individuals); init_individual(child1);
   struct individual *child2 = ep_alloc(ep_individuals); init_individual(child2);
 
@@ -1766,7 +1766,7 @@ void update_map_parts_create(struct placement *p)
 
   for (uns i=0; i<GARY_SIZE(parts); i++)
   {
-    struct map_placement *mp = malloc(sizeof(struct map_placement));
+    struct map_placement *mp = xmalloc(sizeof(struct map_placement));
     mp->placement = p;
     mp->part = parts[i];
 
@@ -1863,7 +1863,7 @@ struct placement **get_closure(struct placement *placement)
 {
   struct placement **closure;
   GARY_INIT(closure, 0);
-  bool *chosen = malloc(GARY_SIZE(placement->individual->placements) * sizeof(bool));
+  bool *chosen = xmalloc(GARY_SIZE(placement->individual->placements) * sizeof(bool));
   for (uns i=0; i<GARY_SIZE(placement->individual->placements); i++) { chosen[i] = 0; }
   chosen[placement->request->ind] = 1;
 
@@ -2033,10 +2033,10 @@ void reset_individual_map(struct individual *i)
     }
 
     free(i->map[j]);
-    struct map_part *part = malloc(sizeof(struct map_part));
+    struct map_part *part = xmalloc(sizeof(struct map_part));
     part->ind = j;
 
-    mp = malloc(sizeof(struct map_placement));
+    mp = xmalloc(sizeof(struct map_placement));
     part->placement = mp;
     mp->placement = &dummy_placement;
     mp->next_in_map = mp->prev_in_map = NULL;
@@ -2145,8 +2145,8 @@ void init_individual(struct individual *individual)
   for (uns j=0; j<num_map_parts; j++)
   {
     GARY_PUSH(individual->map);
-    struct map_part *part = malloc(sizeof(struct map_part));
-    struct map_placement *mp = malloc(sizeof(struct map_placement));
+    struct map_part *part = xmalloc(sizeof(struct map_part));
+    struct map_placement *mp = xmalloc(sizeof(struct map_placement));
     part->placement = mp;
     part->ind = j;
     mp->placement = &dummy_placement;