(build_mission_list_type): Simplify.

(show_mission): Plug memory leak.
This commit is contained in:
Markus Armbruster 2006-03-29 19:46:39 +00:00
parent e8b50af84e
commit 4895745773

View file

@ -68,6 +68,12 @@ struct airport {
natid own; natid own;
}; };
union item_u {
struct shpstr ship;
struct plnstr plane;
struct lndstr land;
};
static void add_airport(struct emp_qelem *, coord, coord); static void add_airport(struct emp_qelem *, coord, coord);
static int air_damage(struct emp_qelem *, coord, coord, int, natid, static int air_damage(struct emp_qelem *, coord, coord, int, natid,
s_char *, int); s_char *, int);
@ -297,28 +303,15 @@ build_mission_list_type(struct genlist *mi, coord x, coord y, int mission,
struct nstr_item ni; struct nstr_item ni;
struct genlist *glp; struct genlist *glp;
struct genitem *gp; struct genitem *gp;
union { union item_u item;
struct shpstr u_sp; int dist;
struct lndstr u_lp;
struct plnstr u_pp;
} u_block;
s_char *block;
int dist, size;
int radius; int radius;
int relat; int relat;
struct sctstr sect; struct sctstr sect;
/*
size = MAX(sizeof(struct shpstr),sizeof(struct lndstr));
size = MAX(size,sizeof(struct plnstr));
block = malloc(size);
*/
size = sizeof(u_block);
block = (s_char *)&u_block;
snxtitem_all(&ni, type); snxtitem_all(&ni, type);
while (nxtitem(&ni, block)) { while (nxtitem(&ni, &item)) {
gp = (struct genitem *)block; gp = (struct genitem *)&item;
if (gp->own == 0) if (gp->own == 0)
continue; continue;
@ -393,8 +386,8 @@ build_mission_list_type(struct genlist *mi, coord x, coord y, int mission,
glp->cp = &plchr[(int)gp->type]; glp->cp = &plchr[(int)gp->type];
break; break;
} }
glp->thing = malloc(size); glp->thing = malloc(sizeof(item));
memcpy(glp->thing, block, size); memcpy(glp->thing, &item, sizeof(item));
emp_insque(&glp->queue, &mi[gp->own].queue); emp_insque(&glp->queue, &mi[gp->own].queue);
} }
} }
@ -878,17 +871,12 @@ mission_name(short int mission)
void void
show_mission(int type, struct nstr_item *np) show_mission(int type, struct nstr_item *np)
{ {
size_t size;
int first = 1, radius; int first = 1, radius;
s_char *block; union item_u item;
struct genitem *gp; struct genitem *gp;
size = MAX(sizeof(struct lndstr), sizeof(struct plnstr)); while (nxtitem(np, &item)) {
size = MAX(size, sizeof(struct shpstr)); gp = (struct genitem *)&item;
block = malloc(size);
while (nxtitem(np, block)) {
gp = (struct genitem *)block;
if (!player->owner || gp->own == 0) if (!player->owner || gp->own == 0)
continue; continue;
@ -916,17 +904,15 @@ show_mission(int type, struct nstr_item *np)
if ((sect.sct_type == SCT_HEADQ) && (sect.sct_effic >= 60)) if ((sect.sct_type == SCT_HEADQ) && (sect.sct_effic >= 60))
plus++; plus++;
if (((struct lndstr *)block)->lnd_rad_max == 0) if (item.land.lnd_rad_max == 0)
plus = 0; plus = 0;
else else
plus += ((struct lndstr *)block)->lnd_rad_max; plus += item.land.lnd_rad_max;
prxy(" %3d,%-3d", gp->x, gp->y, player->cnum); prxy(" %3d,%-3d", gp->x, gp->y, player->cnum);
pr(" %4d", plus); pr(" %4d", plus);
} else if (gp->mission == MI_ESCORT) { } else if (gp->mission == MI_ESCORT) {
pr(" "); pr(" ");
pr(" %4d", (int) pr(" %4d", (int)(item.plane.pln_range / 2.0));
((float)((struct plnstr *)block)->pln_range / 2.0)
);
} else } else
pr(" "); pr(" ");
if (gp->mission) if (gp->mission)