fix crash when reading empty resource maps

This commit is contained in:
Jesús A. Álvarez 2016-04-17 14:15:06 +02:00
parent 2562781a7e
commit 4255947fe4
2 changed files with 3 additions and 3 deletions

View File

@ -68,13 +68,13 @@ struct __attribute__ ((__packed__)) RfMap {
struct __attribute__ ((__packed__)) RfTypeEntry {
// resource type entry
uint32_t type; // resource type
uint16_t count; // number of resources minus one
int16_t count; // number of resources minus one
uint16_t offset; // offset to ref list from type list
};
struct __attribute__ ((__packed__)) RfTypeList {
// resource type list
uint16_t count; // minus one
int16_t count; // minus one
struct RfTypeEntry entry[];
};

2
res.c
View File

@ -280,7 +280,7 @@ RFILE* res_load (RFILE *rp) {
uint8_t *names = ((void*)map)+ntohs(map->nameListOffset);
// read types
rp->numTypes = 1+ntohs(types->count);
rp->numTypes = 1+(int16_t)ntohs(types->count);
rp->types = calloc(rp->numTypes, sizeof(struct RmType));
if (rp->types == NULL) egoto(ENOMEM, error);
bzero(rp->types, sizeof(struct RmType) * rp->numTypes);