(ef_read): Catch null cache.

(ef_read): Used to get the file size again some circumstances; doesn't
make sense, as no other process may be writing this file.

(ef_write): Don't refuse to write beyond record 65536.  This module
can cope with that.  Some users have trouble long before that (short
record numbers), but that should be handled there.

(ef_write): Catch table not file-backed.
This commit is contained in:
Markus Armbruster 2005-10-24 23:16:13 +00:00
parent 880a3e399b
commit ecab7c4f2f

View file

@ -178,7 +178,6 @@ ef_ptr(int type, int id)
if (ef_check(type) < 0) if (ef_check(type) < 0)
return NULL; return NULL;
ep = &empfile[type]; ep = &empfile[type];
if (CANT_HAPPEN(!(ep->flags & EFF_MEM))) if (CANT_HAPPEN(!(ep->flags & EFF_MEM)))
return NULL; return NULL;
@ -200,21 +199,20 @@ ef_read(int type, int id, void *into)
if (ef_check(type) < 0) if (ef_check(type) < 0)
return 0; return 0;
ep = &empfile[type]; ep = &empfile[type];
if (id < 0) if (CANT_HAPPEN(!ep->cache))
return 0; return 0;
if (id < 0)
return 0; /* FIXME can this happen? */
if (id >= ep->fids)
return 0;
if (ep->flags & EFF_MEM) { if (ep->flags & EFF_MEM) {
if (id >= ep->fids) from = ep->cache + id * ep->size;
return 0;
from = ep->cache + (id * ep->size);
} else { } else {
if (id >= ep->fids) { if (ep->baseid + ep->cids <= id || ep->baseid > id) {
ep->fids = fsize(ep->fd) / ep->size;
if (id >= ep->fids)
return 0;
}
if (ep->baseid + ep->cids <= id || ep->baseid > id)
if (fillcache(ep, id) < 1) if (fillcache(ep, id) < 1)
return 0; return 0;
}
from = ep->cache + (id - ep->baseid) * ep->size; from = ep->cache + (id - ep->baseid) * ep->size;
} }
memcpy(into, from, ep->size); memcpy(into, from, ep->size);
@ -318,11 +316,8 @@ ef_write(int type, int id, void *from)
if (ef_check(type) < 0) if (ef_check(type) < 0)
return 0; return 0;
ep = &empfile[type]; ep = &empfile[type];
if (id > 65536) { if (CANT_HAPPEN(ep->fd < 0))
/* largest unit id; this may bite us in large games */
logerror("ef_write: type %d id %d is too large!\n", type, id);
return 0; return 0;
}
if (ep->prewrite) if (ep->prewrite)
ep->prewrite(id, from); ep->prewrite(id, from);
if (CANT_HAPPEN((ep->flags & EFF_MEM) ? id >= ep->fids : id > ep->fids)) if (CANT_HAPPEN((ep->flags & EFF_MEM) ? id >= ep->fids : id > ep->fids))