model: use zero sized arrays for variable sized sprite structs

Also fixes an incorrect use of sizeof which was previously papered
over by the padded size of the struct.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
Kevin Shanahan 2012-11-14 11:54:35 +10:30
parent dc561715a1
commit abfcd14de1
3 changed files with 8 additions and 9 deletions

View File

@ -91,9 +91,8 @@ Mod_LoadSpriteGroup(void *pin, mspriteframe_t **ppframe, const char *loadname,
pingroup = (dspritegroup_t *)pin; pingroup = (dspritegroup_t *)pin;
numframes = LittleLong(pingroup->numframes); numframes = LittleLong(pingroup->numframes);
pspritegroup = Hunk_AllocName(sizeof(mspritegroup_t) + pspritegroup = Hunk_AllocName(sizeof(*pspritegroup) +
(numframes - numframes * sizeof(pspritegroup->frames[0]),
1) * sizeof(pspritegroup->frames[0]),
loadname); loadname);
pspritegroup->numframes = numframes; pspritegroup->numframes = numframes;
@ -138,7 +137,7 @@ Mod_LoadSpriteModel(model_t *mod, void *buffer, const char *loadname)
int size; int size;
dspriteframetype_t *pframetype; dspriteframetype_t *pframetype;
pin = (dsprite_t *) buffer; pin = (dsprite_t *)buffer;
version = LittleLong(pin->version); version = LittleLong(pin->version);
if (version != SPRITE_VERSION) if (version != SPRITE_VERSION)
@ -146,7 +145,7 @@ Mod_LoadSpriteModel(model_t *mod, void *buffer, const char *loadname)
__func__, mod->name, version, SPRITE_VERSION); __func__, mod->name, version, SPRITE_VERSION);
numframes = LittleLong(pin->numframes); numframes = LittleLong(pin->numframes);
size = sizeof(msprite_t) + (numframes - 1) * sizeof(psprite->frames); size = sizeof(*psprite) + numframes * sizeof(psprite->frames[0]);
psprite = Hunk_AllocName(size, loadname); psprite = Hunk_AllocName(size, loadname);
mod->cache.data = psprite; mod->cache.data = psprite;

View File

@ -240,7 +240,7 @@ void R_SpriteDataStore(mspriteframe_t *frame, const char *modelname,
typedef struct { typedef struct {
int numframes; int numframes;
float *intervals; float *intervals;
mspriteframe_t *frames[1]; mspriteframe_t *frames[0]; /* variable sized */
} mspritegroup_t; } mspritegroup_t;
typedef struct { typedef struct {
@ -255,7 +255,7 @@ typedef struct {
int numframes; int numframes;
float beamlength; // remove? float beamlength; // remove?
void *cachespot; // remove? void *cachespot; // remove?
mspriteframedesc_t frames[1]; mspriteframedesc_t frames[0]; /* variable sized */
} msprite_t; } msprite_t;
#ifdef QW_HACK #ifdef QW_HACK

View File

@ -220,7 +220,7 @@ void R_SpriteDataStore(mspriteframe_t *frame, const char *modelname,
typedef struct { typedef struct {
int numframes; int numframes;
float *intervals; float *intervals;
mspriteframe_t *frames[1]; mspriteframe_t *frames[0]; /* variable sized */
} mspritegroup_t; } mspritegroup_t;
typedef struct { typedef struct {
@ -235,7 +235,7 @@ typedef struct {
int numframes; int numframes;
float beamlength; // remove? float beamlength; // remove?
void *cachespot; // remove? void *cachespot; // remove?
mspriteframedesc_t frames[1]; mspriteframedesc_t frames[0]; /* variable sized */
} msprite_t; } msprite_t;