Fix validation of threshold's threshold argument

There were two checks meant to enforce positive numbers, both dating
back to the earliest known versions of the code, and both wrong.

The first one applied only to thresholds given with the command, not
ones prompted for, and it incorrectly rejected numbers starting with +
or prefixed by whitespace.  Remove it.

The second one failed to reject negative numbers when prefixed by
whitespace.  Fix.

Fortunately, the update doesn't conjure up stuff to satisfy negative
thresholds.
This commit is contained in:
Markus Armbruster 2008-07-19 22:35:23 -04:00
parent 3c25ebd927
commit 9031b03b56

View file

@ -58,12 +58,7 @@ thre(void)
if (!snxtsct(&nstr, player->argp[2]))
return RET_SYN;
type = ip->i_uid;
if (player->argp[3] && *player->argp[3] &&
(*player->argp[3] < '0' || *player->argp[3] > '9')) {
pr("Threshold must be a number\n");
return RET_SYN;
}
while (!player->aborted && nxtsct(&nstr, &sect)) {
while (nxtsct(&nstr, &sect)) {
if (!player->owner)
continue;
val = sect.sct_dist[type];
@ -76,12 +71,14 @@ thre(void)
xyas(nstr.x, nstr.y, player->cnum),
dchr[sect.sct_type].d_name);
if ((p = getstarg(player->argp[3], prompt, buf)) == 0)
return RET_FAIL;
return RET_SYN;
if (!*p)
continue;
if (!check_sect_ok(&sect))
return RET_FAIL;
if (*p == '\0' || *p == '-')
continue;
thresh = atoi(p);
if (thresh < 0)
return RET_SYN;
if (thresh > ITEM_MAX)
thresh = ITEM_MAX;
if ((val > 0) && (val == thresh)) {