diff --git a/libs/util/bspfile.c b/libs/util/bspfile.c index c9983689d..9216dd559 100644 --- a/libs/util/bspfile.c +++ b/libs/util/bspfile.c @@ -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) diff --git a/tools/qflight/source/ltface.c b/tools/qflight/source/ltface.c index dfa969e76..baee7b7eb 100644 --- a/tools/qflight/source/ltface.c +++ b/tools/qflight/source/ltface.c @@ -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; } diff --git a/tools/qflight/source/qflight.c b/tools/qflight/source/qflight.c index 4ca393295..80393f620 100644 --- a/tools/qflight/source/qflight.c +++ b/tools/qflight/source/qflight.c @@ -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);