(ef_ptr): Change return type to void *.
(ef_ptr): Use CANT_HAPPEN() to ensure EFF_MEM; check it before less serious index out of range failure.
This commit is contained in:
parent
5030d124a1
commit
f2e6d6b232
3 changed files with 7 additions and 8 deletions
|
@ -131,7 +131,7 @@ struct fileinit {
|
||||||
|
|
||||||
extern struct castr *ef_cadef(int);
|
extern struct castr *ef_cadef(int);
|
||||||
extern int ef_read(int, int, void *);
|
extern int ef_read(int, int, void *);
|
||||||
extern char *ef_ptr(int, int);
|
extern void *ef_ptr(int, int);
|
||||||
extern char *ef_nameof(int);
|
extern char *ef_nameof(int);
|
||||||
extern time_t ef_mtime(int);
|
extern time_t ef_mtime(int);
|
||||||
extern int ef_open(int, int);
|
extern int ef_open(int, int);
|
||||||
|
|
|
@ -171,20 +171,19 @@ ef_flush(int type)
|
||||||
/*
|
/*
|
||||||
* Return a pointer the id 'id' of object of type 'type' in the cache.
|
* Return a pointer the id 'id' of object of type 'type' in the cache.
|
||||||
*/
|
*/
|
||||||
char *
|
void *
|
||||||
ef_ptr(int type, int id)
|
ef_ptr(int type, int id)
|
||||||
{
|
{
|
||||||
struct empfile *ep;
|
struct empfile *ep;
|
||||||
|
|
||||||
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)))
|
||||||
|
return NULL;
|
||||||
if (id < 0 || id >= ep->fids)
|
if (id < 0 || id >= ep->fids)
|
||||||
return NULL;
|
return NULL; /* FIXME can this happen? */
|
||||||
if ((ep->flags & EFF_MEM) == 0) {
|
|
||||||
logerror("ef_ptr: (%s) only valid for EFF_MEM entries", ep->file);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return ep->cache + ep->size * id;
|
return ep->cache + ep->size * id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ nxtitemp(struct nstr_item *np)
|
||||||
} else {
|
} else {
|
||||||
np->cur++;
|
np->cur++;
|
||||||
}
|
}
|
||||||
gp = (struct genitem *)ef_ptr(np->type, np->cur);
|
gp = ef_ptr(np->type, np->cur);
|
||||||
if (gp == (struct genitem *)0)
|
if (gp == (struct genitem *)0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue