diff --git a/src/lib/common/xundump.c b/src/lib/common/xundump.c index cd903ade..b9b8de26 100644 --- a/src/lib/common/xundump.c +++ b/src/lib/common/xundump.c @@ -96,6 +96,16 @@ static int add2symset(int, long *, char *); static int xubody(FILE *); static int xutail(FILE *, struct castr *); +/* + * Does the code hardcode indexes for table TYPE? + */ +static int +have_hardcoded_indexes(int type) +{ + return type == EF_ITEM || type == EF_SECTOR_CHR + || type == EF_INFRASTRUCTURE; +} + /* * Gripe about the current line to stderr, return -1. */ @@ -1053,16 +1063,18 @@ xundump(FILE *fp, char *file, int *plno, int expected_table) if (CANT_HAPPEN(!ca)) return -1; + if (have_hardcoded_indexes(type)) { + may_omit_id = may_trunc = 0; + } else { + may_omit_id = 1; + may_trunc = empfile[type].nent < 0; + } + nca = nf = 0; - may_omit_id = 1; - 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_ARRAY_LEN(&ca[i])); - if (ca[i].ca_flags & NSC_CONST) - may_omit_id = may_trunc = 0; - } } fldca = malloc(nf * sizeof(*fldca)); fldidx = malloc(nf * sizeof(*fldidx)); diff --git a/tests/empdump/errors.err b/tests/empdump/errors.err index 54258d3a..abc4e324 100644 --- a/tests/empdump/errors.err +++ b/tests/empdump/errors.err @@ -74,7 +74,7 @@ tests/empdump/xundump-errors/fld-unexpid:6: Table's first part doesn't have this tests/empdump/xundump-errors/fld-unexpid1:7: Value for field 1 must be 2 tests/empdump/xundump-errors/fld-unksym:2: Unknown level symbol `xxx' in field 11 tests/empdump/xundump-errors/fld-unparen:2: Unmatched '(' in field 19 -tests/empdump/xundump-errors/ftr-fewrows:2: Expected 1024 more rows +tests/empdump/xundump-errors/ftr-fewrows:2: Expected 34 more rows tests/empdump/xundump-errors/ftr-fewrows2:4: Expected 13 more rows tests/empdump/xundump-errors/ftr-fewrows3:4: Expected 1 more rows tests/empdump/xundump-errors/ftr-fewrows4:7: Expected row with 2 in field 1, like in table's first part diff --git a/tests/empdump/xundump-errors/ftr-fewrows b/tests/empdump/xundump-errors/ftr-fewrows index 0be2020f..b1fbff52 100644 --- a/tests/empdump/xundump-errors/ftr-fewrows +++ b/tests/empdump/xundump-errors/ftr-fewrows @@ -1,3 +1,3 @@ -XDUMP sect 0 +XDUMP sect-chr 0 /0 -# Expected 1024 more rows +# Expected 34 more rows