mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
fix a few memory access bugs
This commit is contained in:
parent
00294f7ae0
commit
dd5cac488c
3 changed files with 17 additions and 11 deletions
|
@ -183,9 +183,12 @@ LoadBSPFile (QFile *file, int size)
|
|||
#define SET_LUMP(l,n) \
|
||||
do { \
|
||||
bsp->num##n = LittleLong (header->lumps[l].filelen); \
|
||||
bsp->n = malloc (bsp->num##n); \
|
||||
memcpy (bsp->n, (byte *) header + LittleLong (header->lumps[l].fileofs), \
|
||||
bsp->num##n); \
|
||||
if (bsp->num##n) { \
|
||||
bsp->n = malloc (bsp->num##n); \
|
||||
memcpy (bsp->n, \
|
||||
(byte *) header + LittleLong (header->lumps[l].fileofs), \
|
||||
bsp->num##n); \
|
||||
} \
|
||||
bsp->num##n /= sizeof (bsp->n[0]); \
|
||||
} while (0)
|
||||
|
||||
|
@ -206,9 +209,12 @@ do { \
|
|||
#define SET_LUMP(l,n) \
|
||||
do { \
|
||||
bsp->n##size = LittleLong (header->lumps[l].filelen); \
|
||||
bsp->n = malloc (bsp->n##size); \
|
||||
memcpy (bsp->n, (byte *) header + LittleLong (header->lumps[l].fileofs), \
|
||||
bsp->n##size); \
|
||||
if (bsp->n##size) { \
|
||||
bsp->n = malloc (bsp->n##size); \
|
||||
memcpy (bsp->n, \
|
||||
(byte *) header + LittleLong (header->lumps[l].fileofs), \
|
||||
bsp->n##size); \
|
||||
} \
|
||||
bsp->n##size /= sizeof (bsp->n[0]); \
|
||||
} while (0)
|
||||
|
||||
|
|
|
@ -453,7 +453,7 @@ void
|
|||
LightFace (int surfnum)
|
||||
{
|
||||
int ofs;
|
||||
byte *out;
|
||||
byte *out, *outdata;
|
||||
dface_t *f;
|
||||
int lightmapwidth, lightmapsize, size, c, i, j, s, t, w, h;
|
||||
lightinfo_t l;
|
||||
|
@ -516,7 +516,7 @@ LightFace (int surfnum)
|
|||
lightmapsize = size * l.numlightstyles;
|
||||
|
||||
LOCK;
|
||||
out = malloc (lightmapsize);
|
||||
outdata = out = malloc (lightmapsize);
|
||||
UNLOCK;
|
||||
ofs = GetFileSpace (lightmapsize);
|
||||
f->lightofs = ofs;
|
||||
|
@ -550,7 +550,7 @@ LightFace (int surfnum)
|
|||
}
|
||||
}
|
||||
LOCK;
|
||||
memcpy (lightdata->str + ofs, out, lightmapsize);
|
||||
free (out);
|
||||
memcpy (lightdata->str + ofs, outdata, lightmapsize);
|
||||
free (outdata);
|
||||
UNLOCK;
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ GetFileSpace (int size)
|
|||
int ofs;
|
||||
|
||||
LOCK;
|
||||
lightdata->size = (lightdata->size + 3) & 3;
|
||||
lightdata->size = (lightdata->size + 3) & ~3;
|
||||
ofs = lightdata->size;
|
||||
lightdata->size += size;
|
||||
dstring_adjust (lightdata);
|
||||
|
|
Loading…
Reference in a new issue