Verify table uid sanity more tightly

verify_row() refrains from rejecting zero uids, because some tables
may contain blank entries, with zero uid.

Change it to check only header sanity for entries that are not in use.
This filters out all legitimately blank entries.  Tighten up the uid
check.

For computing "in use", factor empobj_in_use() out of xdvisible().
Note that xdvisible()'s case EF_COUNTRY doesn't bother to check
nat_stat, because that's implied by what it does check.  It's not
implied in empobj_in_use(), so add it there.
This commit is contained in:
Markus Armbruster 2011-04-25 09:34:11 +02:00
parent fbf5b78129
commit b30c83cd64
4 changed files with 60 additions and 39 deletions

View file

@ -36,7 +36,9 @@
#include "empobj.h"
#include "file.h"
#include "news.h"
#include "optlist.h"
#include "product.h"
char *
empobj_chr_name(struct empobj *gp)
@ -73,3 +75,45 @@ get_empobj_mob_max(int type)
CANT_REACH();
return -1;
}
int
empobj_in_use(int type, void *p)
{
switch (type) {
case EF_SHIP:
case EF_PLANE:
case EF_LAND:
case EF_NUKE:
case EF_TRADE:
case EF_COMM:
case EF_LOST:
return ((struct empobj *)p)->own != 0;
case EF_NATION:
case EF_COUNTRY:
return ((struct natstr *)p)->nat_stat != STAT_UNUSED;
case EF_NEWS:
return ((struct nwsstr *)p)->nws_vrb != 0;
case EF_TREATY:
return ((struct trtstr *)p)->trt_status != TS_FREE;
case EF_LOAN:
return ((struct lonstr *)p)->l_status != LS_FREE;
case EF_REALM:
return empobj_in_use(EF_NATION,
ef_ptr(EF_NATION,
((struct realmstr *)p)->r_cnum));
case EF_PRODUCT:
return ((struct pchrstr *)p)->p_sname[0];
case EF_SHIP_CHR:
return ((struct mchrstr *)p)->m_name[0];
case EF_PLANE_CHR:
return ((struct plchrstr *)p)->pl_name[0];
case EF_LAND_CHR:
return ((struct lchrstr *)p)->l_name[0];
case EF_NUKE_CHR:
return ((struct nchrstr *)p)->n_name[0];
case EF_NEWS_CHR:
return ((struct rptstr *)p)->r_newspage != 0;
default:
return 1;
}
}