From: Markus Armbruster Date: Sun, 22 May 2011 09:05:01 +0000 (+0200) Subject: Clean up xundump's test whether table may be truncated X-Git-Tag: v4.3.28~58 X-Git-Url: http://git.pond.sub.org/?p=empserver;a=commitdiff_plain;h=3a3b9409b2910e452e6b39a036549876ece2217a 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. --- diff --git a/src/lib/common/xundump.c b/src/lib/common/xundump.c index 53f2a4a50..515f2863e 100644 --- a/src/lib/common/xundump.c +++ b/src/lib/common/xundump.c @@ -81,6 +81,7 @@ static struct castr **fldca; /* Map field number to selector */ static int *fldidx; /* Map field number to index */ static int *caflds; /* Map selector number to #fields seen */ 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 deffld(int, char *, int); @@ -985,10 +986,14 @@ xundump(FILE *fp, char *file, int *plno, int expected_table) return -1; nca = nf = 0; + may_trunc = empfile[type].nent < 0; for (i = 0; ca[i].ca_name; i++) { 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); + if (ca[i].ca_flags & NSC_CONST) + may_trunc = 0; + } } fldca = malloc(nf * sizeof(*fldca)); fldidx = malloc(nf * sizeof(*fldidx)); @@ -1064,9 +1069,7 @@ xubody(FILE *fp) if (CANT_HAPPEN(maxid > ep->fids)) maxid = ep->fids; if (maxid < ep->fids) { - if (ep->nent < 0 - && (EF_IS_GAME_STATE(cur_type) - || (cur_type >= EF_SHIP_CHR && cur_type <= EF_NUKE_CHR))) { + if (may_trunc) { if (!ef_truncate(cur_type, maxid)) return -1; } else