Clean up xundump's test whether table may be truncated

A table may be truncated when its size is variable and it doesn't have
const fields.  The old code tested table IDs instead.
This commit is contained in:
Markus Armbruster 2011-05-22 11:05:01 +02:00
parent 63f972d31c
commit 3a3b9409b2

View file

@ -81,6 +81,7 @@ static struct castr **fldca; /* Map field number to selector */
static int *fldidx; /* Map field number to index */ static int *fldidx; /* Map field number to index */
static int *caflds; /* Map selector number to #fields seen */ static int *caflds; /* Map selector number to #fields seen */
static int *cafldspp; /* ditto, in previous parts */ static int *cafldspp; /* ditto, in previous parts */
static int may_trunc; /* Okay to truncate? */
static int gripe(char *, ...) ATTRIBUTE((format (printf, 1, 2))); static int gripe(char *, ...) ATTRIBUTE((format (printf, 1, 2)));
static int deffld(int, char *, int); static int deffld(int, char *, int);
@ -985,10 +986,14 @@ xundump(FILE *fp, char *file, int *plno, int expected_table)
return -1; return -1;
nca = nf = 0; nca = nf = 0;
may_trunc = empfile[type].nent < 0;
for (i = 0; ca[i].ca_name; i++) { for (i = 0; ca[i].ca_name; i++) {
nca++; nca++;
if (!(ca[i].ca_flags & NSC_EXTRA)) if (!(ca[i].ca_flags & NSC_EXTRA)) {
nf += MAX(1, ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0); nf += MAX(1, ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0);
if (ca[i].ca_flags & NSC_CONST)
may_trunc = 0;
}
} }
fldca = malloc(nf * sizeof(*fldca)); fldca = malloc(nf * sizeof(*fldca));
fldidx = malloc(nf * sizeof(*fldidx)); fldidx = malloc(nf * sizeof(*fldidx));
@ -1064,9 +1069,7 @@ xubody(FILE *fp)
if (CANT_HAPPEN(maxid > ep->fids)) if (CANT_HAPPEN(maxid > ep->fids))
maxid = ep->fids; maxid = ep->fids;
if (maxid < ep->fids) { if (maxid < ep->fids) {
if (ep->nent < 0 if (may_trunc) {
&& (EF_IS_GAME_STATE(cur_type)
|| (cur_type >= EF_SHIP_CHR && cur_type <= EF_NUKE_CHR))) {
if (!ef_truncate(cur_type, maxid)) if (!ef_truncate(cur_type, maxid))
return -1; return -1;
} else } else