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

@ -28,7 +28,7 @@
*
* Known contributors to this file:
* Ron Koenderink, 2005
* Markus Armbruster, 2006-2010
* Markus Armbruster, 2006-2011
*/
#include <config.h>
@ -36,10 +36,10 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "empobj.h"
#include "file.h"
#include "misc.h"
#include "nsc.h"
#include "plane.h"
#include "product.h"
static void verify_fail(int, int, struct castr *, int, char *, ...)
@ -130,7 +130,7 @@ static int
verify_row(int type, int row)
{
struct castr *ca = ef_cadef(type);
struct emptypedstr *row_ref;
struct empobj *row_ref;
int i, j, n;
struct valstr val;
int ret_val = 0;
@ -150,6 +150,9 @@ verify_row(int type, int row)
}
}
if (!empobj_in_use(type, row_ref))
return ret_val;
for (i = 0; ca[i].ca_name; ++i) {
if (ca[i].ca_get)
continue; /* virtual */
@ -166,10 +169,6 @@ verify_row(int type, int row)
}
if (ca[i].ca_table == type && i == 0) {
/* uid */
/* Some files contain zeroed records, cope */
/* TODO tighten this check */
if (val.val_as.lng == 0)
continue;
if (val.val_as.lng != row) {
verify_fail(type, row, &ca[i], j,
"value is %ld instead of %d",