Check ef_type before dereferencing struct empobj
Such manual checking is error prone, but the best we can do right now.
This commit is contained in:
parent
990b39edec
commit
5490782db3
7 changed files with 52 additions and 9 deletions
|
@ -67,6 +67,9 @@ do_look(short type)
|
||||||
unsigned char *bitmap;
|
unsigned char *bitmap;
|
||||||
int changed = 0;
|
int changed = 0;
|
||||||
|
|
||||||
|
if (CANT_HAPPEN(type != EF_LAND && type != EF_SHIP))
|
||||||
|
type = EF_SHIP;
|
||||||
|
|
||||||
if (!snxtitem(&ni, type, player->argp[1]))
|
if (!snxtitem(&ni, type, player->argp[1]))
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
if ((bitmap = malloc((WORLD_X * WORLD_Y) / 8)) == 0) {
|
if ((bitmap = malloc((WORLD_X * WORLD_Y) / 8)) == 0) {
|
||||||
|
|
|
@ -61,6 +61,9 @@ radar(short type)
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
char prompt[80];
|
char prompt[80];
|
||||||
|
|
||||||
|
if (CANT_HAPPEN(type != EF_LAND && type != EF_SHIP))
|
||||||
|
type = EF_SHIP;
|
||||||
|
|
||||||
sprintf(prompt, "Radar from (%s # or sector(s)) : ", ef_nameof(type));
|
sprintf(prompt, "Radar from (%s # or sector(s)) : ", ef_nameof(type));
|
||||||
cp = getstarg(player->argp[1], prompt, buf);
|
cp = getstarg(player->argp[1], prompt, buf);
|
||||||
|
|
||||||
|
|
|
@ -349,6 +349,10 @@ unit_map(int unit_type, int uid, struct nstr_sect *nsp, char *originp)
|
||||||
struct range range;
|
struct range range;
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
|
if (CANT_HAPPEN((ef_flags(unit_type) & (EFF_OWNER | EFF_XY))
|
||||||
|
!= (EFF_OWNER | EFF_XY)))
|
||||||
|
return RET_FAIL;
|
||||||
|
|
||||||
if (!get_empobj(unit_type, uid, &unit))
|
if (!get_empobj(unit_type, uid, &unit))
|
||||||
return RET_FAIL;
|
return RET_FAIL;
|
||||||
if (!player->owner || unit.gen.own == 0)
|
if (!player->owner || unit.gen.own == 0)
|
||||||
|
|
|
@ -622,6 +622,9 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
|
||||||
else
|
else
|
||||||
emp_insque(&plp->queue, &bombers);
|
emp_insque(&plp->queue, &bombers);
|
||||||
plane_owner = plp->plane.pln_own;
|
plane_owner = plp->plane.pln_own;
|
||||||
|
} else {
|
||||||
|
CANT_REACH();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!QEMPTY(&missiles)) {
|
if (!QEMPTY(&missiles)) {
|
||||||
|
@ -1327,6 +1330,8 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list,
|
||||||
next = qp->q_forw;
|
next = qp->q_forw;
|
||||||
glp = (struct genlist *)qp;
|
glp = (struct genlist *)qp;
|
||||||
gp = glp->thing;
|
gp = glp->thing;
|
||||||
|
if (CANT_HAPPEN(gp->ef_type != EF_PLANE))
|
||||||
|
break;
|
||||||
|
|
||||||
dist = mapdist(x, y, gp->x, gp->y);
|
dist = mapdist(x, y, gp->x, gp->y);
|
||||||
|
|
||||||
|
|
|
@ -72,26 +72,33 @@ nxtitem(struct nstr_item *np, void *ptr)
|
||||||
case NS_ALL:
|
case NS_ALL:
|
||||||
break;
|
break;
|
||||||
case NS_DIST:
|
case NS_DIST:
|
||||||
|
if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_XY)))
|
||||||
|
return 0;
|
||||||
if (!xyinrange(gp->x, gp->y, &np->range)) {
|
if (!xyinrange(gp->x, gp->y, &np->range)) {
|
||||||
selected = 0;
|
selected = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
np->curdist = mapdist((int)gp->x, (int)gp->y,
|
np->curdist = mapdist(gp->x, gp->y, np->cx, np->cy);
|
||||||
(int)np->cx, (int)np->cy);
|
|
||||||
if (np->curdist > np->dist)
|
if (np->curdist > np->dist)
|
||||||
selected = 0;
|
selected = 0;
|
||||||
break;
|
break;
|
||||||
case NS_AREA:
|
case NS_AREA:
|
||||||
|
if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_XY)))
|
||||||
|
return 0;
|
||||||
if (!xyinrange(gp->x, gp->y, &np->range))
|
if (!xyinrange(gp->x, gp->y, &np->range))
|
||||||
selected = 0;
|
selected = 0;
|
||||||
if (gp->x == np->range.hx || gp->y == np->range.hy)
|
if (gp->x == np->range.hx || gp->y == np->range.hy)
|
||||||
selected = 0;
|
selected = 0;
|
||||||
break;
|
break;
|
||||||
case NS_XY:
|
case NS_XY:
|
||||||
|
if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_XY)))
|
||||||
|
return 0;
|
||||||
if (xnorm(gp->x) != np->cx || ynorm(gp->y) != np->cy)
|
if (xnorm(gp->x) != np->cx || ynorm(gp->y) != np->cy)
|
||||||
selected = 0;
|
selected = 0;
|
||||||
break;
|
break;
|
||||||
case NS_GROUP:
|
case NS_GROUP:
|
||||||
|
if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_GROUP)))
|
||||||
|
return 0;
|
||||||
if (np->group != gp->group)
|
if (np->group != gp->group)
|
||||||
selected = 0;
|
selected = 0;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -45,16 +45,20 @@ unit_list(struct emp_qelem *unit_list)
|
||||||
struct emp_qelem *qp;
|
struct emp_qelem *qp;
|
||||||
struct emp_qelem *next;
|
struct emp_qelem *next;
|
||||||
struct ulist *ulp;
|
struct ulist *ulp;
|
||||||
|
int type;
|
||||||
struct empobj *unit;
|
struct empobj *unit;
|
||||||
struct lndstr *lnd;
|
struct lndstr *lnd;
|
||||||
struct shpstr *shp;
|
struct shpstr *shp;
|
||||||
|
|
||||||
CANT_HAPPEN(QEMPTY(unit_list));
|
if (CANT_HAPPEN(QEMPTY(unit_list)))
|
||||||
|
return;
|
||||||
qp = unit_list->q_back;
|
qp = unit_list->q_back;
|
||||||
ulp = (struct ulist *)qp;
|
ulp = (struct ulist *)qp;
|
||||||
|
type = ulp->unit.ef_type;
|
||||||
|
if (CANT_HAPPEN(type != EF_LAND && type != EF_SHIP))
|
||||||
|
return;
|
||||||
|
|
||||||
if (ulp->unit.ef_type == EF_LAND)
|
if (type == EF_LAND)
|
||||||
pr("lnd# land type x,y a eff sh gun xl mu tech retr fuel\n");
|
pr("lnd# land type x,y a eff sh gun xl mu tech retr fuel\n");
|
||||||
else
|
else
|
||||||
pr("shp# ship type x,y fl eff mil sh gun pn he xl ln mob tech\n");
|
pr("shp# ship type x,y fl eff mil sh gun pn he xl ln mob tech\n");
|
||||||
|
@ -65,12 +69,14 @@ unit_list(struct emp_qelem *unit_list)
|
||||||
lnd = &ulp->unit.land;
|
lnd = &ulp->unit.land;
|
||||||
shp = &ulp->unit.ship;
|
shp = &ulp->unit.ship;
|
||||||
unit = &ulp->unit.gen;
|
unit = &ulp->unit.gen;
|
||||||
|
if (CANT_HAPPEN(type != unit->ef_type))
|
||||||
|
continue;
|
||||||
pr("%4d ", unit->uid);
|
pr("%4d ", unit->uid);
|
||||||
pr("%-16.16s ", emp_obj_chr_name(unit));
|
pr("%-16.16s ", emp_obj_chr_name(unit));
|
||||||
prxy("%4d,%-4d ", unit->x, unit->y, unit->own);
|
prxy("%4d,%-4d ", unit->x, unit->y, unit->own);
|
||||||
pr("%1.1s", &unit->group);
|
pr("%1.1s", &unit->group);
|
||||||
pr("%4d%%", unit->effic);
|
pr("%4d%%", unit->effic);
|
||||||
if (unit->ef_type == EF_LAND) {
|
if (type == EF_LAND) {
|
||||||
pr("%4d", lnd->lnd_item[I_SHELL]);
|
pr("%4d", lnd->lnd_item[I_SHELL]);
|
||||||
pr("%4d", lnd->lnd_item[I_GUN]);
|
pr("%4d", lnd->lnd_item[I_GUN]);
|
||||||
count_land_planes(lnd);
|
count_land_planes(lnd);
|
||||||
|
@ -88,7 +94,7 @@ unit_list(struct emp_qelem *unit_list)
|
||||||
}
|
}
|
||||||
pr("%4d", unit->mobil);
|
pr("%4d", unit->mobil);
|
||||||
pr("%4d", unit->tech);
|
pr("%4d", unit->tech);
|
||||||
if (unit->ef_type == EF_LAND) {
|
if (type == EF_LAND) {
|
||||||
pr("%4d%%", lnd->lnd_retreat);
|
pr("%4d%%", lnd->lnd_retreat);
|
||||||
pr("%5d", lnd->lnd_fuel);
|
pr("%5d", lnd->lnd_fuel);
|
||||||
}
|
}
|
||||||
|
@ -108,6 +114,9 @@ unit_put(struct emp_qelem *list, natid actor)
|
||||||
while (qp != list) {
|
while (qp != list) {
|
||||||
ulp = (struct ulist *)qp;
|
ulp = (struct ulist *)qp;
|
||||||
unit = &ulp->unit.gen;
|
unit = &ulp->unit.gen;
|
||||||
|
if (CANT_HAPPEN(unit->ef_type != EF_LAND
|
||||||
|
&& unit->ef_type != EF_SHIP))
|
||||||
|
continue;
|
||||||
if (actor) {
|
if (actor) {
|
||||||
mpr(actor, "%s stopped at %s\n", obj_nameof(unit),
|
mpr(actor, "%s stopped at %s\n", obj_nameof(unit),
|
||||||
xyas(unit->x, unit->y, unit->own));
|
xyas(unit->x, unit->y, unit->own));
|
||||||
|
@ -137,6 +146,9 @@ unit_path(int together, struct empobj *unit, char *buf)
|
||||||
double dummy;
|
double dummy;
|
||||||
int mtype;
|
int mtype;
|
||||||
|
|
||||||
|
if (CANT_HAPPEN(unit->ef_type != EF_LAND && unit->ef_type != EF_SHIP))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (!sarg_xy(buf, &destx, &desty))
|
if (!sarg_xy(buf, &destx, &desty))
|
||||||
return 0;
|
return 0;
|
||||||
if (!together) {
|
if (!together) {
|
||||||
|
@ -182,6 +194,8 @@ unit_view(struct emp_qelem *list)
|
||||||
for (qp = list->q_back; qp != list; qp = next) {
|
for (qp = list->q_back; qp != list; qp = next) {
|
||||||
next = qp->q_back;
|
next = qp->q_back;
|
||||||
ulp = (struct ulist *)qp;
|
ulp = (struct ulist *)qp;
|
||||||
|
if (CANT_HAPPEN(!(ef_flags(ulp->unit.ef_type) & EFF_XY)))
|
||||||
|
continue;
|
||||||
getsect(ulp->unit.gen.x, ulp->unit.gen.y, §);
|
getsect(ulp->unit.gen.x, ulp->unit.gen.y, §);
|
||||||
if (ulp->unit.ef_type == EF_SHIP) {
|
if (ulp->unit.ef_type == EF_SHIP) {
|
||||||
if (((struct mchrstr *)ulp->chrp)->m_flags & M_FOOD)
|
if (((struct mchrstr *)ulp->chrp)->m_flags & M_FOOD)
|
||||||
|
|
|
@ -67,26 +67,33 @@ nxtitemp(struct nstr_item *np)
|
||||||
case NS_ALL:
|
case NS_ALL:
|
||||||
break;
|
break;
|
||||||
case NS_DIST:
|
case NS_DIST:
|
||||||
|
if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_XY)))
|
||||||
|
return 0;
|
||||||
if (!xyinrange(gp->x, gp->y, &np->range)) {
|
if (!xyinrange(gp->x, gp->y, &np->range)) {
|
||||||
selected = 0;
|
selected = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
np->curdist = mapdist((int)gp->x, (int)gp->y,
|
np->curdist = mapdist(gp->x, gp->y, np->cx, np->cy);
|
||||||
(int)np->cx, (int)np->cy);
|
|
||||||
if (np->curdist > np->dist)
|
if (np->curdist > np->dist)
|
||||||
selected = 0;
|
selected = 0;
|
||||||
break;
|
break;
|
||||||
case NS_AREA:
|
case NS_AREA:
|
||||||
|
if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_XY)))
|
||||||
|
return 0;
|
||||||
if (!xyinrange(gp->x, gp->y, &np->range))
|
if (!xyinrange(gp->x, gp->y, &np->range))
|
||||||
selected = 0;
|
selected = 0;
|
||||||
if (gp->x == np->range.hx || gp->y == np->range.hy)
|
if (gp->x == np->range.hx || gp->y == np->range.hy)
|
||||||
selected = 0;
|
selected = 0;
|
||||||
break;
|
break;
|
||||||
case NS_XY:
|
case NS_XY:
|
||||||
|
if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_XY)))
|
||||||
|
return 0;
|
||||||
if (xnorm(gp->x) != np->cx || ynorm(gp->y) != np->cy)
|
if (xnorm(gp->x) != np->cx || ynorm(gp->y) != np->cy)
|
||||||
selected = 0;
|
selected = 0;
|
||||||
break;
|
break;
|
||||||
case NS_GROUP:
|
case NS_GROUP:
|
||||||
|
if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_GROUP)))
|
||||||
|
return 0;
|
||||||
if (np->group != gp->group)
|
if (np->group != gp->group)
|
||||||
selected = 0;
|
selected = 0;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue