Clean up how snxtitem() parses country names

Old code didn't check for natarg() failure, but relied on
sarg_type("-1") returning NS_UNDEF.
This commit is contained in:
Markus Armbruster 2008-07-20 10:49:50 -04:00
parent fc00db8f5d
commit bd34378900

View file

@ -55,11 +55,10 @@ snxtitem(struct nstr_item *np, int type, char *str)
{ {
struct range range; struct range range;
int list[NS_LSIZE]; int list[NS_LSIZE];
int n; int cnum, n;
coord cx, cy; coord cx, cy;
int dist; int dist;
int flags; int flags;
char natnumber[16];
char prompt[128]; char prompt[128];
char buf[1024]; char buf[1024];
@ -76,8 +75,11 @@ snxtitem(struct nstr_item *np, int type, char *str)
return 0; return 0;
} }
if (type == EF_NATION && isalpha(*str)) { if (type == EF_NATION && isalpha(*str)) {
sprintf(natnumber, "%d", natarg(str, NULL)); cnum = natarg(str, NULL);
str = natnumber; if (cnum < 0)
return 0;
sprintf(buf, "%d", cnum);
str = buf;
} }
flags = ef_flags(type); flags = ef_flags(type);
switch (sarg_type(str)) { switch (sarg_type(str)) {