fix a few memory access bugs

This commit is contained in:
Bill Currie 2002-09-20 22:44:29 +00:00
parent 00294f7ae0
commit dd5cac488c
3 changed files with 17 additions and 11 deletions

View file

@ -183,9 +183,12 @@ LoadBSPFile (QFile *file, int size)
#define SET_LUMP(l,n) \ #define SET_LUMP(l,n) \
do { \ do { \
bsp->num##n = LittleLong (header->lumps[l].filelen); \ bsp->num##n = LittleLong (header->lumps[l].filelen); \
if (bsp->num##n) { \
bsp->n = malloc (bsp->num##n); \ bsp->n = malloc (bsp->num##n); \
memcpy (bsp->n, (byte *) header + LittleLong (header->lumps[l].fileofs), \ memcpy (bsp->n, \
(byte *) header + LittleLong (header->lumps[l].fileofs), \
bsp->num##n); \ bsp->num##n); \
} \
bsp->num##n /= sizeof (bsp->n[0]); \ bsp->num##n /= sizeof (bsp->n[0]); \
} while (0) } while (0)
@ -206,9 +209,12 @@ do { \
#define SET_LUMP(l,n) \ #define SET_LUMP(l,n) \
do { \ do { \
bsp->n##size = LittleLong (header->lumps[l].filelen); \ bsp->n##size = LittleLong (header->lumps[l].filelen); \
if (bsp->n##size) { \
bsp->n = malloc (bsp->n##size); \ bsp->n = malloc (bsp->n##size); \
memcpy (bsp->n, (byte *) header + LittleLong (header->lumps[l].fileofs), \ memcpy (bsp->n, \
(byte *) header + LittleLong (header->lumps[l].fileofs), \
bsp->n##size); \ bsp->n##size); \
} \
bsp->n##size /= sizeof (bsp->n[0]); \ bsp->n##size /= sizeof (bsp->n[0]); \
} while (0) } while (0)

View file

@ -453,7 +453,7 @@ void
LightFace (int surfnum) LightFace (int surfnum)
{ {
int ofs; int ofs;
byte *out; byte *out, *outdata;
dface_t *f; dface_t *f;
int lightmapwidth, lightmapsize, size, c, i, j, s, t, w, h; int lightmapwidth, lightmapsize, size, c, i, j, s, t, w, h;
lightinfo_t l; lightinfo_t l;
@ -516,7 +516,7 @@ LightFace (int surfnum)
lightmapsize = size * l.numlightstyles; lightmapsize = size * l.numlightstyles;
LOCK; LOCK;
out = malloc (lightmapsize); outdata = out = malloc (lightmapsize);
UNLOCK; UNLOCK;
ofs = GetFileSpace (lightmapsize); ofs = GetFileSpace (lightmapsize);
f->lightofs = ofs; f->lightofs = ofs;
@ -550,7 +550,7 @@ LightFace (int surfnum)
} }
} }
LOCK; LOCK;
memcpy (lightdata->str + ofs, out, lightmapsize); memcpy (lightdata->str + ofs, outdata, lightmapsize);
free (out); free (outdata);
UNLOCK; UNLOCK;
} }

View file

@ -83,7 +83,7 @@ GetFileSpace (int size)
int ofs; int ofs;
LOCK; LOCK;
lightdata->size = (lightdata->size + 3) & 3; lightdata->size = (lightdata->size + 3) & ~3;
ofs = lightdata->size; ofs = lightdata->size;
lightdata->size += size; lightdata->size += size;
dstring_adjust (lightdata); dstring_adjust (lightdata);