Fix satellite to fail on bad conditional

snxtsct() and snxtitem() fail when the condition argument is bad.
satmap() didn't check for failure.  Due to the way snxtsct() and
snxtitem() work, bad condition arguments were reported and otherwise
ignored.
This commit is contained in:
Markus Armbruster 2011-04-08 21:06:56 +02:00
parent d0a6dffa02
commit 74a69cf74c
3 changed files with 20 additions and 17 deletions

View file

@ -585,7 +585,7 @@ extern int sarg_list(char *, int *, int);
/* satmap.c */ /* satmap.c */
extern void satdisp_sect(struct sctstr *, int); extern void satdisp_sect(struct sctstr *, int);
extern void satdisp_units(coord, coord); extern void satdisp_units(coord, coord);
extern void satmap(int, int, int, int, int, int); extern int satmap(int, int, int, int, int, int);
extern void sathead(void); extern void sathead(void);
/* sect.c */ /* sect.c */
extern void sct_postread(int, void *); extern void sct_postread(int, void *);

View file

@ -86,8 +86,6 @@ sate(void)
pr("Satellite Map Report:\n"); pr("Satellite Map Report:\n");
pr("%s at ", prplane(&plane)); pr("%s at ", prplane(&plane));
tech = techfact(plane.pln_tech, 20.0); tech = techfact(plane.pln_tech, 20.0);
satmap(plane.pln_x, plane.pln_y, plane.pln_effic, return satmap(plane.pln_x, plane.pln_y, plane.pln_effic,
(int)tech, plchr[(int)plane.pln_type].pl_flags, type); (int)tech, plchr[(int)plane.pln_type].pl_flags, type);
return RET_OK;
} }

View file

@ -28,6 +28,7 @@
* *
* Known contributors to this file: * Known contributors to this file:
* Steve McClure, 2000 * Steve McClure, 2000
* Markus Armbruster, 2004-2011
*/ */
#include <config.h> #include <config.h>
@ -50,7 +51,7 @@
static char **rad; static char **rad;
static char *radbuf; static char *radbuf;
void int
satmap(int x, int y, int eff, int range, int flags, int type) satmap(int x, int y, int eff, int range, int flags, int type)
{ {
struct sctstr sect; struct sctstr sect;
@ -68,7 +69,7 @@ satmap(int x, int y, int eff, int range, int flags, int type)
char selection[1024]; char selection[1024];
if (!eff) if (!eff)
return; return RET_OK;
if (!radbuf) if (!radbuf)
radbuf = malloc(WORLD_Y * MAPWIDTH(1)); radbuf = malloc(WORLD_Y * MAPWIDTH(1));
@ -82,7 +83,7 @@ satmap(int x, int y, int eff, int range, int flags, int type)
if (!radbuf || !rad) { if (!radbuf || !rad) {
pr("Memory error in satmap, tell the deity.\n"); pr("Memory error in satmap, tell the deity.\n");
return; return RET_FAIL;
} }
range = range * (eff / 100.0); range = range * (eff / 100.0);
@ -100,9 +101,10 @@ satmap(int x, int y, int eff, int range, int flags, int type)
sprintf(selection, "@%s:%d", xyas(x, y, player->cnum), range); sprintf(selection, "@%s:%d", xyas(x, y, player->cnum), range);
if (type == EF_BAD || type == EF_SECTOR) { if (type == EF_BAD || type == EF_SECTOR) {
if (type == EF_SECTOR) /* Use ?conditionals */ if (type == EF_SECTOR) { /* Use ?conditionals */
snxtsct(&ns, selection); if (!snxtsct(&ns, selection))
else return RET_SYN;
} else
snxtsct_dist(&ns, x, y, range); snxtsct_dist(&ns, x, y, range);
blankfill(radbuf, &ns.range, 1); blankfill(radbuf, &ns.range, 1);
@ -143,9 +145,10 @@ satmap(int x, int y, int eff, int range, int flags, int type)
if ((type == EF_BAD || type == EF_SHIP) && if ((type == EF_BAD || type == EF_SHIP) &&
(flags & P_S || flags & P_I)) { (flags & P_S || flags & P_I)) {
if (type == EF_SHIP) if (type == EF_SHIP) {
snxtitem(&ni, EF_SHIP, selection, NULL); if (!snxtitem(&ni, EF_SHIP, selection, NULL))
else return RET_SYN;
} else
snxtitem_dist(&ni, EF_SHIP, x, y, range); snxtitem_dist(&ni, EF_SHIP, x, y, range);
crackle = count = 0; crackle = count = 0;
@ -188,9 +191,10 @@ satmap(int x, int y, int eff, int range, int flags, int type)
if ((type == EF_BAD || type == EF_LAND) && if ((type == EF_BAD || type == EF_LAND) &&
(flags & P_S || flags & P_I)) { (flags & P_S || flags & P_I)) {
if (type == EF_LAND) if (type == EF_LAND) {
snxtitem(&ni, EF_LAND, selection, NULL); if (!snxtitem(&ni, EF_LAND, selection, NULL))
else return RET_SYN;
} else
snxtitem_dist(&ni, EF_LAND, x, y, range); snxtitem_dist(&ni, EF_LAND, x, y, range);
crackle = count = 0; crackle = count = 0;
@ -247,6 +251,7 @@ satmap(int x, int y, int eff, int range, int flags, int type)
pr("%s\n", rad[row]); pr("%s\n", rad[row]);
pr("\n(c) 1989 Imaginative Images Inc.\n"); pr("\n(c) 1989 Imaginative Images Inc.\n");
} }
return RET_OK;
} }
void void