]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
q3map2: use safe_malloc0 when safe_malloc is followed by a memset to 0 with the same... 160/head
authorThomas Debesse <dev@illwieckz.net>
Thu, 23 Jan 2020 21:27:12 +0000 (22:27 +0100)
committerThomas Debesse <dev@illwieckz.net>
Thu, 23 Jan 2020 21:27:12 +0000 (22:27 +0100)
26 files changed:
tools/quake3/common/bspfile.c
tools/quake3/common/cmdlib.c
tools/quake3/common/imagelib.c
tools/quake3/common/polylib.c
tools/quake3/q3map2/brush.c
tools/quake3/q3map2/bsp.c
tools/quake3/q3map2/bspfile_abstract.c
tools/quake3/q3map2/bspfile_ibsp.c
tools/quake3/q3map2/bspfile_rbsp.c
tools/quake3/q3map2/convert_bsp.c
tools/quake3/q3map2/decals.c
tools/quake3/q3map2/facebsp.c
tools/quake3/q3map2/light.c
tools/quake3/q3map2/light_bounce.c
tools/quake3/q3map2/light_ydnar.c
tools/quake3/q3map2/lightmaps_ydnar.c
tools/quake3/q3map2/map.c
tools/quake3/q3map2/model.c
tools/quake3/q3map2/patch.c
tools/quake3/q3map2/portals.c
tools/quake3/q3map2/shaders.c
tools/quake3/q3map2/surface.c
tools/quake3/q3map2/surface_foliage.c
tools/quake3/q3map2/surface_meta.c
tools/quake3/q3map2/vis.c
tools/quake3/q3map2/visflow.c

index 4fc45bd6af7d347f9d6bbf4d44e7c9c8e555f944..c65da46d593dfa9dbd3b9dba7c2d34d6edb8e284 100644 (file)
@@ -96,9 +96,7 @@ void SetLightBytes( int n ){
                return;
        }
 
-       lightBytes = safe_malloc_info( numLightBytes, "SetLightBytes" );
-
-       memset( lightBytes, 0, numLightBytes );
+       lightBytes = safe_malloc0_info( numLightBytes, "SetLightBytes" );
 }
 
 void SetGridPoints( int n ){
@@ -112,9 +110,7 @@ void SetGridPoints( int n ){
                return;
        }
 
-       gridData = safe_malloc_info( numGridPoints * 8, "SetGridPoints" );
-
-       memset( gridData, 0, numGridPoints * 8 );
+       gridData = safe_malloc0_info( numGridPoints * 8, "SetGridPoints" );
 }
 
 void IncDrawVerts(){
@@ -152,9 +148,7 @@ void SetDrawVerts( int n ){
        numDrawVerts = n;
        numDrawVertsBuffer = numDrawVerts;
 
-       drawVerts = safe_malloc_info( sizeof( drawVert_t ) * numDrawVertsBuffer, "IncDrawVerts" );
-
-       memset( drawVerts, 0, n * sizeof( drawVert_t ) );
+       drawVerts = safe_malloc0_info( sizeof( drawVert_t ) * numDrawVertsBuffer, "IncDrawVerts" );
 }
 
 void SetDrawSurfacesBuffer(){
@@ -164,9 +158,7 @@ void SetDrawSurfacesBuffer(){
 
        numDrawSurfacesBuffer = MAX_MAP_DRAW_SURFS;
 
-       drawSurfaces = safe_malloc_info( sizeof( dsurface_t ) * numDrawSurfacesBuffer, "IncDrawSurfaces" );
-
-       memset( drawSurfaces, 0, MAX_MAP_DRAW_SURFS * sizeof( drawVert_t ) );
+       drawSurfaces = safe_malloc0_info( sizeof( dsurface_t ) * numDrawSurfacesBuffer, "IncDrawSurfaces" );
 }
 
 void SetDrawSurfaces( int n ){
@@ -177,9 +169,7 @@ void SetDrawSurfaces( int n ){
        numDrawSurfaces = n;
        numDrawSurfacesBuffer = numDrawSurfaces;
 
-       drawSurfaces = safe_malloc_info( sizeof( dsurface_t ) * numDrawSurfacesBuffer, "IncDrawSurfaces" );
-
-       memset( drawSurfaces, 0, n * sizeof( drawVert_t ) );
+       drawSurfaces = safe_malloc0_info( sizeof( dsurface_t ) * numDrawSurfacesBuffer, "IncDrawSurfaces" );
 }
 
 void BspFilesCleanup(){
@@ -522,8 +512,7 @@ void StripTrailing( char *e ) {
 epair_t *ParseEpair( void ) {
        epair_t *e;
 
-       e = safe_malloc( sizeof( epair_t ) );
-       memset( e, 0, sizeof( epair_t ) );
+       e = safe_malloc0( sizeof( epair_t ) );
 
        if ( strlen( token ) >= MAX_KEY - 1 ) {
                Error( "ParseEpar: token too long" );
index 43bf0a35e7fc3a22acc56d6f77e71a0ed12c5598..abbc0d68968807d7a18f5adb24d86c5becebbff4 100644 (file)
@@ -675,8 +675,7 @@ int    LoadFileBlock( const char *filename, void **bufferptr ){
        if ( nBlock > 0 ) {
                nAllocSize += MEM_BLOCKSIZE - nBlock;
        }
-       buffer = safe_malloc( nAllocSize + 1 );
-       memset( buffer, 0, nAllocSize + 1 );
+       buffer = safe_malloc0( nAllocSize + 1 );
        SafeRead( f, buffer, length );
        fclose( f );
 
index 5bc5ff71df9a0e2fee1c039f4224d2f300d17057..661b9ed32436e7aa3fd9c6dc9713857ac6bafd2b 100644 (file)
@@ -256,8 +256,7 @@ void LoadLBM( const char *filename, byte **picture, byte **palette ){
                        break;
 
                case CMAPID:
-                       cmapbuffer = safe_malloc( 768 );
-                       memset( cmapbuffer, 0, 768 );
+                       cmapbuffer = safe_malloc0( 768 );
                        memcpy( cmapbuffer, LBM_P, chunklength );
                        break;
 
@@ -572,8 +571,7 @@ void WritePCXfile( const char *filename, byte *data,
        pcx_t   *pcx;
        byte        *pack;
 
-       pcx = safe_malloc( width * height * 2 + 1000 );
-       memset( pcx, 0, sizeof( *pcx ) );
+       pcx = safe_malloc0( width * height * 2 + 1000 );
 
        pcx->manufacturer = 0x0a;   // PCX id
        pcx->version = 5;           // 256 color
@@ -1145,6 +1143,8 @@ void WriteTGA( const char *filename, byte *data, int width, int height ) {
        FILE    *f;
 
        buffer = safe_malloc( width * height * 4 + 18 );
+       /* we may also use safe_malloc0 on the whole instead,
+        * this would just be a bit slower */
        memset( buffer, 0, 18 );
        buffer[2] = 2;      // uncompressed type
        buffer[12] = width & 255;
index bef8fbd4d917313a0880d335a58daf75e3744641..21afcbcc9b3d2e482c61775c4912c6857f4ac05c 100644 (file)
@@ -66,8 +66,7 @@ winding_t   *AllocWinding( int points ){
                }
        }
        s = sizeof( *w ) + ( points ? sizeof( w->p[0] ) * ( points - 1 ) : 0 );
-       w = safe_malloc( s );
-       memset( w, 0, s );
+       w = safe_malloc0( s );
        return w;
 }
 
@@ -94,8 +93,7 @@ winding_accu_t *AllocWindingAccu( int points ){
                }
        }
        s = sizeof( *w ) + ( points ? sizeof( w->p[0] ) * ( points - 1 ) : 0 );
-       w = safe_malloc( s );
-       memset( w, 0, s );
+       w = safe_malloc0( s );
        return w;
 }
 
index c6400cbc1ac3fc4859e2e917a34b3516b7c754bb..db04b8805e2faf08bc61ec8993df13e5c09964d8 100644 (file)
@@ -98,8 +98,7 @@ brush_t *AllocBrush( int numSides ){
                Error( "AllocBrush called with numsides = %d", numSides );
        }
        c = (size_t)&( ( (brush_t*) 0 )->sides[ numSides ] );
-       bb = safe_malloc( c );
-       memset( bb, 0, c );
+       bb = safe_malloc0( c );
        if ( numthreads == 1 ) {
                numActiveBrushes++;
        }
@@ -829,8 +828,7 @@ void FilterStructuralBrushesIntoTree( entity_t *e, tree_t *tree ) {
 tree_t *AllocTree( void ){
        tree_t  *tree;
 
-       tree = safe_malloc( sizeof( *tree ) );
-       memset( tree, 0, sizeof( *tree ) );
+       tree = safe_malloc0( sizeof( *tree ) );
        ClearBounds( tree->mins, tree->maxs );
 
        return tree;
@@ -844,8 +842,7 @@ tree_t *AllocTree( void ){
 node_t *AllocNode( void ){
        node_t  *node;
 
-       node = safe_malloc( sizeof( *node ) );
-       memset( node, 0, sizeof( *node ) );
+       node = safe_malloc0( sizeof( *node ) );
 
        return node;
 }
index b3c28002aaf5c91c4df3e6d41142d7a08d4a22ed..432de5d538af48580903a12e7d253380b1584958 100644 (file)
@@ -719,8 +719,7 @@ int BSPMain( int argc, char **argv ){
        Sys_Printf( "--- BSP ---\n" );
 
        SetDrawSurfacesBuffer();
-       mapDrawSurfs = safe_malloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
-       memset( mapDrawSurfs, 0, sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
+       mapDrawSurfs = safe_malloc0( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
        numMapDrawSurfs = 0;
 
        tempSource[ 0 ] = '\0';
index 62beb16a141b6409d4066c939cb0c579f4bc1eee..80b1028b384257ce684eeaba4d51facffc471b39 100644 (file)
@@ -89,9 +89,7 @@ void SetDrawVerts( int n ){
        numBSPDrawVerts = n;
        numBSPDrawVertsBuffer = numBSPDrawVerts;
 
-       bspDrawVerts = safe_malloc_info( sizeof( bspDrawVert_t ) * numBSPDrawVertsBuffer, "IncDrawVerts" );
-
-       memset( bspDrawVerts, 0, n * sizeof( bspDrawVert_t ) );
+       bspDrawVerts = safe_malloc0_info( sizeof( bspDrawVert_t ) * numBSPDrawVertsBuffer, "IncDrawVerts" );
 }
 
 int numBSPDrawSurfacesBuffer = 0;
@@ -102,9 +100,7 @@ void SetDrawSurfacesBuffer(){
 
        numBSPDrawSurfacesBuffer = MAX_MAP_DRAW_SURFS;
 
-       bspDrawSurfaces = safe_malloc_info( sizeof( bspDrawSurface_t ) * numBSPDrawSurfacesBuffer, "IncDrawSurfaces" );
-
-       memset( bspDrawSurfaces, 0, MAX_MAP_DRAW_SURFS * sizeof( bspDrawSurface_t ) );
+       bspDrawSurfaces = safe_malloc0_info( sizeof( bspDrawSurface_t ) * numBSPDrawSurfacesBuffer, "IncDrawSurfaces" );
 }
 
 void SetDrawSurfaces( int n ){
@@ -115,9 +111,7 @@ void SetDrawSurfaces( int n ){
        numBSPDrawSurfaces = n;
        numBSPDrawSurfacesBuffer = numBSPDrawSurfaces;
 
-       bspDrawSurfaces = safe_malloc_info( sizeof( bspDrawSurface_t ) * numBSPDrawSurfacesBuffer, "IncDrawSurfaces" );
-
-       memset( bspDrawSurfaces, 0, n * sizeof( bspDrawSurface_t ) );
+       bspDrawSurfaces = safe_malloc0_info( sizeof( bspDrawSurface_t ) * numBSPDrawSurfacesBuffer, "IncDrawSurfaces" );
 }
 
 void BSPFilesCleanup(){
@@ -500,8 +494,7 @@ epair_t *ParseEPair( void ){
 
 
        /* allocate and clear new epair */
-       e = safe_malloc( sizeof( epair_t ) );
-       memset( e, 0, sizeof( epair_t ) );
+       e = safe_malloc0( sizeof( epair_t ) );
 
        /* handle key */
        if ( strlen( token ) >= ( MAX_KEY - 1 ) ) {
index f610abc8396e62c7b9b3500652f307720271add6..1c4c994a894fb5fad23ea32e5b6cc472b1aa503f 100644 (file)
@@ -120,8 +120,7 @@ static void AddBrushSidesLump( FILE *file, ibspHeader_t *header ){
 
        /* allocate output buffer */
        size = numBSPBrushSides * sizeof( *buffer );
-       buffer = safe_malloc( size );
-       memset( buffer, 0, size );
+       buffer = safe_malloc0( size );
 
        /* convert */
        in = bspBrushSides;
@@ -232,8 +231,7 @@ static void AddDrawSurfacesLump( FILE *file, ibspHeader_t *header ){
 
        /* allocate output buffer */
        size = numBSPDrawSurfaces * sizeof( *buffer );
-       buffer = safe_malloc( size );
-       memset( buffer, 0, size );
+       buffer = safe_malloc0( size );
 
        /* convert */
        in = bspDrawSurfaces;
@@ -330,8 +328,7 @@ static void AddDrawVertsLump( FILE *file, ibspHeader_t *header ){
 
        /* allocate output buffer */
        size = numBSPDrawVerts * sizeof( *buffer );
-       buffer = safe_malloc( size );
-       memset( buffer, 0, size );
+       buffer = safe_malloc0( size );
 
        /* convert */
        in = bspDrawVerts;
@@ -385,8 +382,7 @@ static void CopyLightGridLumps( ibspHeader_t *header ){
        numBSPGridPoints = GetLumpElements( (bspHeader_t*) header, LUMP_LIGHTGRID, sizeof( *in ) );
 
        /* allocate buffer */
-       bspGridPoints = safe_malloc( numBSPGridPoints * sizeof( *bspGridPoints ) );
-       memset( bspGridPoints, 0, numBSPGridPoints * sizeof( *bspGridPoints ) );
+       bspGridPoints = safe_malloc0( numBSPGridPoints * sizeof( *bspGridPoints ) );
 
        /* copy */
        in = GetLump( (bspHeader_t*) header, LUMP_LIGHTGRID );
index b1ff0304dde7dd4888c53e77b6ae5df054cc12d6..88ebcbf4e8dc5705ba9363c5bd1af7375582bbfa 100644 (file)
@@ -96,8 +96,7 @@ static void CopyLightGridLumps( rbspHeader_t *header ){
        numBSPGridPoints = GetLumpElements( (bspHeader_t*) header, LUMP_LIGHTARRAY, sizeof( *inArray ) );
 
        /* allocate buffer */
-       bspGridPoints = safe_malloc( numBSPGridPoints * sizeof( *bspGridPoints ) );
-       memset( bspGridPoints, 0, numBSPGridPoints * sizeof( *bspGridPoints ) );
+       bspGridPoints = safe_malloc0( numBSPGridPoints * sizeof( *bspGridPoints ) );
 
        /* copy */
        inArray = GetLump( (bspHeader_t*) header, LUMP_LIGHTARRAY );
index 87579d26e32561f28c2512ba66d242fef3ebe113..9a0e05516e239e274470fea2a26fc3a4a67d7e58 100644 (file)
@@ -49,8 +49,7 @@ void PseudoCompileBSP( qboolean need_tree, const char *BSPFilePath, const char *
        int i;
 
        SetDrawSurfacesBuffer();
-       mapDrawSurfs = safe_malloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
-       memset( mapDrawSurfs, 0, sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
+       mapDrawSurfs = safe_malloc0( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
        numMapDrawSurfs = 0;
 
        BeginBSPFile();
index f7471c96ccea19869331abff927a067d81371b6f..dfa8dacec7e37636a6bfa34e267d4a493fded792 100644 (file)
@@ -620,8 +620,7 @@ static void ProjectDecalOntoWinding( decalProjector_t *dp, mapDrawSurface_t *ds,
        ds2->lightmapScale = ds->lightmapScale;
        ds2->shadeAngleDegrees = ds->shadeAngleDegrees;
        ds2->numVerts = w->numpoints;
-       ds2->verts = safe_malloc( ds2->numVerts * sizeof( *ds2->verts ) );
-       memset( ds2->verts, 0, ds2->numVerts * sizeof( *ds2->verts ) );
+       ds2->verts = safe_malloc0( ds2->numVerts * sizeof( *ds2->verts ) );
 
        /* set vertexes */
        for ( i = 0; i < ds2->numVerts; i++ )
index e5390ede45a1fcc32da6a2893b4df1d17674e161..48cf798de98f0ef99ae14441b994626ea0ed1084 100644 (file)
@@ -49,8 +49,7 @@ int c_faceLeafs;
 face_t  *AllocBspFace( void ) {
        face_t  *f;
 
-       f = safe_malloc( sizeof( *f ) );
-       memset( f, 0, sizeof( *f ) );
+       f = safe_malloc0( sizeof( *f ) );
 
        return f;
 }
index 45546f7c8a7acb1a8ab7fcc8d8cb0955bc831f3d..e43906e0aadfc87f34a0636f5424a66d3c65b4a3 100644 (file)
@@ -107,8 +107,7 @@ static void CreateSunLight( sun_t *sun ){
 
                /* create a light */
                numSunLights++;
-               light = safe_malloc( sizeof( *light ) );
-               memset( light, 0, sizeof( *light ) );
+               light = safe_malloc0( sizeof( *light ) );
                light->next = lights;
                lights = light;
 
@@ -254,8 +253,7 @@ void CreateEntityLights( void ){
 
                /* create a light */
                numPointLights++;
-               light = safe_malloc( sizeof( *light ) );
-               memset( light, 0, sizeof( *light ) );
+               light = safe_malloc0( sizeof( *light ) );
                light->next = lights;
                lights = light;
 
@@ -592,8 +590,7 @@ void CreateSurfaceLights( void ){
                        VectorScale( origin, 0.5f, origin );
 
                        /* create a light */
-                       light = safe_malloc( sizeof( *light ) );
-                       memset( light, 0, sizeof( *light ) );
+                       light = safe_malloc0( sizeof( *light ) );
                        light->next = lights;
                        lights = light;
 
@@ -1857,14 +1854,12 @@ void SetupGrid( void ){
        numBSPGridPoints = numRawGridPoints;
 
        /* allocate lightgrid */
-       rawGridPoints = safe_malloc( numRawGridPoints * sizeof( *rawGridPoints ) );
-       memset( rawGridPoints, 0, numRawGridPoints * sizeof( *rawGridPoints ) );
+       rawGridPoints = safe_malloc0( numRawGridPoints * sizeof( *rawGridPoints ) );
 
        if ( bspGridPoints != NULL ) {
                free( bspGridPoints );
        }
-       bspGridPoints = safe_malloc( numBSPGridPoints * sizeof( *bspGridPoints ) );
-       memset( bspGridPoints, 0, numBSPGridPoints * sizeof( *bspGridPoints ) );
+       bspGridPoints = safe_malloc0( numBSPGridPoints * sizeof( *bspGridPoints ) );
 
        /* clear lightgrid */
        for ( i = 0; i < numRawGridPoints; i++ )
index 9fe00ef68c57dd7d7f5876739be47d86fd0eeffa..02fd8ebd482042c0f461e7993752c2ecf2b4993e 100644 (file)
@@ -532,8 +532,7 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw
        }
 
        /* create a light */
-       light = safe_malloc( sizeof( *light ) );
-       memset( light, 0, sizeof( *light ) );
+       light = safe_malloc0( sizeof( *light ) );
 
        /* attach it */
        ThreadLock();
@@ -579,8 +578,7 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw
                /* optionally create a point splashsplash light for first pass */
                if ( original && si->backsplashFraction > 0 ) {
                        /* allocate a new point light */
-                       splash = safe_malloc( sizeof( *splash ) );
-                       memset( splash, 0, sizeof( *splash ) );
+                       splash = safe_malloc0( sizeof( *splash ) );
                        splash->next = lights;
                        lights = splash;
 
index c75dac2e55f5705029df32059d2eec071a09031d..19d1b31a6d1f8c291fbd2188a38b4151e8fea31e 100644 (file)
@@ -162,13 +162,11 @@ void SmoothNormals( void ){
 
 
        /* allocate shade angle table */
-       shadeAngles = safe_malloc( numBSPDrawVerts * sizeof( float ) );
-       memset( shadeAngles, 0, numBSPDrawVerts * sizeof( float ) );
+       shadeAngles = safe_malloc0( numBSPDrawVerts * sizeof( float ) );
 
        /* allocate smoothed table */
        cs = ( numBSPDrawVerts / 8 ) + 1;
-       smoothed = safe_malloc( cs );
-       memset( smoothed, 0, cs );
+       smoothed = safe_malloc0( cs );
 
        /* set default shade angle */
        defaultShadeAngle = DEG2RAD( shadeAngleDegrees );
@@ -2392,8 +2390,7 @@ void IlluminateRawLightmap( int rawLightmapNum ){
                        if ( lm->superLuxels[ lightmapNum ] == NULL ) {
                                /* allocate sampling lightmap storage */
                                size = lm->sw * lm->sh * SUPER_LUXEL_SIZE * sizeof( float );
-                               lm->superLuxels[ lightmapNum ] = safe_malloc( size );
-                               memset( lm->superLuxels[ lightmapNum ], 0, size );
+                               lm->superLuxels[ lightmapNum ] = safe_malloc0( size );
                        }
 
                        /* set style */
index f578daad0df2aa9750b640df1ababff3889c740c..f6203f538652e52d9aefd4297ca56f9fa47f54d7 100644 (file)
@@ -67,6 +67,8 @@ void WriteTGA24( char *filename, byte *data, int width, int height, qboolean fli
 
        /* allocate a buffer and set it up */
        buffer = safe_malloc( width * height * 3 + 18 );
+       /* we may also use safe_malloc0 on the whole instead,
+        * this would just be a bit slower */
        memset( buffer, 0, 18 );
        buffer[ 2 ] = 2;
        buffer[ 12 ] = width & 255;
@@ -809,8 +811,7 @@ qboolean AddSurfaceToRawLightmap( int num, rawLightmap_t *lm ){
        /* for planar surfaces, create lightmap vectors for st->xyz conversion */
        if ( VectorLength( ds->lightmapVecs[ 2 ] ) || 1 ) {  /* ydnar: can't remember what exactly i was thinking here... */
                /* allocate space for the vectors */
-               lm->vecs = safe_malloc( 3 * sizeof( vec3_t ) );
-               memset( lm->vecs, 0, 3 * sizeof( vec3_t ) );
+               lm->vecs = safe_malloc0( 3 * sizeof( vec3_t ) );
                VectorCopy( ds->lightmapVecs[ 2 ], lm->vecs[ 2 ] );
 
                /* project stepped lightmap blocks and subtract to get planevecs */
@@ -980,18 +981,15 @@ void SetupSurfaceLightmaps( void ){
        /* allocate a list of surface clusters */
        numSurfaceClusters = 0;
        maxSurfaceClusters = numBSPLeafSurfaces;
-       surfaceClusters = safe_malloc( maxSurfaceClusters * sizeof( *surfaceClusters ) );
-       memset( surfaceClusters, 0, maxSurfaceClusters * sizeof( *surfaceClusters ) );
+       surfaceClusters = safe_malloc0( maxSurfaceClusters * sizeof( *surfaceClusters ) );
 
        /* allocate a list for per-surface info */
-       surfaceInfos = safe_malloc( numBSPDrawSurfaces * sizeof( *surfaceInfos ) );
-       memset( surfaceInfos, 0, numBSPDrawSurfaces * sizeof( *surfaceInfos ) );
+       surfaceInfos = safe_malloc0( numBSPDrawSurfaces * sizeof( *surfaceInfos ) );
        for ( i = 0; i < numBSPDrawSurfaces; i++ )
                surfaceInfos[ i ].childSurfaceNum = -1;
 
        /* allocate a list of surface indexes to be sorted */
-       sortSurfaces = safe_malloc( numBSPDrawSurfaces * sizeof( int ) );
-       memset( sortSurfaces, 0, numBSPDrawSurfaces * sizeof( int ) );
+       sortSurfaces = safe_malloc0( numBSPDrawSurfaces * sizeof( int ) );
 
        /* walk each model in the bsp */
        for ( i = 0; i < numBSPModels; i++ )
@@ -1111,14 +1109,12 @@ void SetupSurfaceLightmaps( void ){
 
        /* allocate a list of surfaces that would go into raw lightmaps */
        numLightSurfaces = 0;
-       lightSurfaces = safe_malloc( numSurfsLightmapped * sizeof( int ) );
-       memset( lightSurfaces, 0, numSurfsLightmapped * sizeof( int ) );
+       lightSurfaces = safe_malloc0( numSurfsLightmapped * sizeof( int ) );
 
        /* allocate a list of raw lightmaps */
        numRawSuperLuxels = 0;
        numRawLightmaps = 0;
-       rawLightmaps = safe_malloc( numSurfsLightmapped * sizeof( *rawLightmaps ) );
-       memset( rawLightmaps, 0, numSurfsLightmapped * sizeof( *rawLightmaps ) );
+       rawLightmaps = safe_malloc0( numSurfsLightmapped * sizeof( *rawLightmaps ) );
 
        /* walk the list of sorted surfaces */
        for ( i = 0; i < numBSPDrawSurfaces; i++ )
@@ -1203,10 +1199,8 @@ void SetupSurfaceLightmaps( void ){
        /* allocate vertex luxel storage */
        for ( k = 0; k < MAX_LIGHTMAPS; k++ )
        {
-               vertexLuxels[ k ] = safe_malloc( numBSPDrawVerts * VERTEX_LUXEL_SIZE * sizeof( float ) );
-               memset( vertexLuxels[ k ], 0, numBSPDrawVerts * VERTEX_LUXEL_SIZE * sizeof( float ) );
-               radVertexLuxels[ k ] = safe_malloc( numBSPDrawVerts * VERTEX_LUXEL_SIZE * sizeof( float ) );
-               memset( radVertexLuxels[ k ], 0, numBSPDrawVerts * VERTEX_LUXEL_SIZE * sizeof( float ) );
+               vertexLuxels[ k ] = safe_malloc0( numBSPDrawVerts * VERTEX_LUXEL_SIZE * sizeof( float ) );
+               radVertexLuxels[ k ] = safe_malloc0( numBSPDrawVerts * VERTEX_LUXEL_SIZE * sizeof( float ) );
        }
 
        /* emit some stats */
@@ -1957,13 +1951,10 @@ static void SetupOutLightmap( rawLightmap_t *lm, outLightmap_t *olm ){
        olm->numShaders = 0;
 
        /* allocate buffers */
-       olm->lightBits = safe_malloc( ( olm->customWidth * olm->customHeight / 8 ) + 8 );
-       memset( olm->lightBits, 0, ( olm->customWidth * olm->customHeight / 8 ) + 8 );
-       olm->bspLightBytes = safe_malloc( olm->customWidth * olm->customHeight * 3 );
-       memset( olm->bspLightBytes, 0, olm->customWidth * olm->customHeight * 3 );
+       olm->lightBits = safe_malloc0( ( olm->customWidth * olm->customHeight / 8 ) + 8 );
+       olm->bspLightBytes = safe_malloc0( olm->customWidth * olm->customHeight * 3 );
        if ( deluxemap ) {
-               olm->bspDirBytes = safe_malloc( olm->customWidth * olm->customHeight * 3 );
-               memset( olm->bspDirBytes, 0, olm->customWidth * olm->customHeight * 3 );
+               olm->bspDirBytes = safe_malloc0( olm->customWidth * olm->customHeight * 3 );
        }
 }
 
@@ -2526,8 +2517,7 @@ void StoreSurfaceLightmaps( qboolean fastLightmapSearch, qboolean storeForReal )
                        /* allocate bsp luxel storage */
                        if ( lm->bspLuxels[ lightmapNum ] == NULL ) {
                                size = lm->w * lm->h * BSP_LUXEL_SIZE * sizeof( float );
-                               lm->bspLuxels[ lightmapNum ] = safe_malloc( size );
-                               memset( lm->bspLuxels[ lightmapNum ], 0, size );
+                               lm->bspLuxels[ lightmapNum ] = safe_malloc0( size );
                        }
 
                        /* allocate radiosity lightmap storage */
@@ -3126,8 +3116,7 @@ void StoreSurfaceLightmaps( qboolean fastLightmapSearch, qboolean storeForReal )
                else
                {
                        numBSPLightBytes = ( numBSPLightmaps * game->lightmapSize * game->lightmapSize * 3 );
-                       bspLightBytes = safe_malloc( numBSPLightBytes );
-                       memset( bspLightBytes, 0, numBSPLightBytes );
+                       bspLightBytes = safe_malloc0( numBSPLightBytes );
                }
 
                /* walk the list of output lightmaps */
index 22fc166fc3773b8a45bfaf444552982fe9bf45f9..ff6eb98f62d1da84cef6d526911b91df016aa878 100644 (file)
@@ -1523,8 +1523,7 @@ void LoadEntityIndexMap( entity_t *e ){
        }
 
        /* create a new index map */
-       im = safe_malloc( sizeof( *im ) );
-       memset( im, 0, sizeof( *im ) );
+       im = safe_malloc0( sizeof( *im ) );
 
        /* set it up */
        im->w = w;
index c8558a3f64e097a1066e86b15e7e40161203559f..effaf17d36523df9b05bfa37c7562605912689e5 100644 (file)
@@ -441,12 +441,10 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
 
                /* set particulars */
                ds->numVerts = PicoGetSurfaceNumVertexes( surface );
-               ds->verts = safe_malloc( ds->numVerts * sizeof( ds->verts[ 0 ] ) );
-               memset( ds->verts, 0, ds->numVerts * sizeof( ds->verts[ 0 ] ) );
+               ds->verts = safe_malloc0( ds->numVerts * sizeof( ds->verts[ 0 ] ) );
 
                ds->numIndexes = PicoGetSurfaceNumIndexes( surface );
-               ds->indexes = safe_malloc( ds->numIndexes * sizeof( ds->indexes[ 0 ] ) );
-               memset( ds->indexes, 0, ds->numIndexes * sizeof( ds->indexes[ 0 ] ) );
+               ds->indexes = safe_malloc0( ds->numIndexes * sizeof( ds->indexes[ 0 ] ) );
 
                /* copy vertexes */
                for ( i = 0; i < ds->numVerts; i++ )
index 82ff09a7e1498c225f82671f4318dfbf17f69fb1..95d478f647f3d5b0833bd8a2178aede53c5b40c0 100644 (file)
@@ -348,8 +348,7 @@ void ParsePatch( qboolean onlyLights ){
        }
 
        /* allocate patch mesh */
-       pm = safe_malloc( sizeof( *pm ) );
-       memset( pm, 0, sizeof( *pm ) );
+       pm = safe_malloc0( sizeof( *pm ) );
 
        /* ydnar: add entity/brush numbering */
        pm->entityNum = mapEnt->mapEntityNum;
@@ -445,8 +444,7 @@ void PatchMapDrawSurfs( entity_t *e ){
        if ( !patchCount ) {
                return;
        }
-       bordering = safe_malloc( patchCount * patchCount );
-       memset( bordering, 0, patchCount * patchCount );
+       bordering = safe_malloc0( patchCount * patchCount );
 
        // build the bordering matrix
        for ( k = 0 ; k < patchCount ; k++ ) {
index 676fa31599df4754276c9580b5e532edd709912c..27ae8c31f31d8705d0eb06109ba3323386c69b6d 100644 (file)
@@ -62,8 +62,7 @@ portal_t *AllocPortal( void ){
                c_peak_portals = c_active_portals;
        }
 
-       p = safe_malloc( sizeof( portal_t ) );
-       memset( p, 0, sizeof( portal_t ) );
+       p = safe_malloc0( sizeof( portal_t ) );
 
        return p;
 }
index 97d98fb1a05b4ba668b32ea451db5f2082f5555c..b3697e4e2afdb40dd0a449fdc53ca4a5734cc601 100644 (file)
@@ -1280,8 +1280,7 @@ static void ParseShaderFile( const char *filename ){
                                }
 
                                /* allocate sun */
-                               sun = safe_malloc( sizeof( *sun ) );
-                               memset( sun, 0, sizeof( *sun ) );
+                               sun = safe_malloc0( sizeof( *sun ) );
 
                                /* set style */
                                sun->style = si->lightStyle;
@@ -1381,8 +1380,7 @@ static void ParseShaderFile( const char *filename ){
                                        surfaceModel_t  *model;
 
                                        /* allocate new model and attach it */
-                                       model = safe_malloc( sizeof( *model ) );
-                                       memset( model, 0, sizeof( *model ) );
+                                       model = safe_malloc0( sizeof( *model ) );
                                        model->next = si->surfaceModel;
                                        si->surfaceModel = model;
 
@@ -1415,8 +1413,7 @@ static void ParseShaderFile( const char *filename ){
 
 
                                        /* allocate new foliage struct and attach it */
-                                       foliage = safe_malloc( sizeof( *foliage ) );
-                                       memset( foliage, 0, sizeof( *foliage ) );
+                                       foliage = safe_malloc0( sizeof( *foliage ) );
                                        foliage->next = si->foliage;
                                        si->foliage = foliage;
 
@@ -1746,8 +1743,7 @@ static void ParseShaderFile( const char *filename ){
                                        alpha = ( !Q_stricmp( token, "q3map_alphaGen" ) || !Q_stricmp( token, "q3map_alphaMod" ) ) ? 1 : 0;
 
                                        /* allocate new colormod */
-                                       cm = safe_malloc( sizeof( *cm ) );
-                                       memset( cm, 0, sizeof( *cm ) );
+                                       cm = safe_malloc0( sizeof( *cm ) );
 
                                        /* attach to shader */
                                        if ( si->colorMod == NULL ) {
index a51db8c176c7e91f59c67e183da6db59bcc3f137..4f69a2f165a6a8be084b759168c0d5cf2324ba67 100644 (file)
@@ -961,8 +961,7 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin
        ds->sampleSize = b->lightmapSampleSize;
        ds->lightmapScale = b->lightmapScale;
        ds->numVerts = w->numpoints;
-       ds->verts = safe_malloc( ds->numVerts * sizeof( *ds->verts ) );
-       memset( ds->verts, 0, ds->numVerts * sizeof( *ds->verts ) );
+       ds->verts = safe_malloc0( ds->numVerts * sizeof( *ds->verts ) );
 
        /* compute s/t coordinates from brush primitive texture matrix (compute axis base) */
        ComputeAxisBase( mapplanes[ s->planenum ].normal, texX, texY );
@@ -3032,8 +3031,7 @@ static void MakeDebugPortalSurfs_r( node_t *node, shaderInfo_t *si ){
                        VectorCopy( p->plane.normal, ds->lightmapVecs[ 2 ] );
                        ds->fogNum = -1;
                        ds->numVerts = w->numpoints;
-                       ds->verts = safe_malloc( ds->numVerts * sizeof( *ds->verts ) );
-                       memset( ds->verts, 0, ds->numVerts * sizeof( *ds->verts ) );
+                       ds->verts = safe_malloc0( ds->numVerts * sizeof( *ds->verts ) );
 
                        /* walk the winding */
                        for ( i = 0; i < ds->numVerts; i++ )
@@ -3124,11 +3122,9 @@ void MakeFogHullSurfs( entity_t *e, tree_t *tree, char *shader ){
        ds->shaderInfo = si;
        ds->fogNum = -1;
        ds->numVerts = 8;
-       ds->verts = safe_malloc( ds->numVerts * sizeof( *ds->verts ) );
-       memset( ds->verts, 0, ds->numVerts * sizeof( *ds->verts ) );
+       ds->verts = safe_malloc0( ds->numVerts * sizeof( *ds->verts ) );
        ds->numIndexes = 36;
-       ds->indexes = safe_malloc( ds->numIndexes * sizeof( *ds->indexes ) );
-       memset( ds->indexes, 0, ds->numIndexes * sizeof( *ds->indexes ) );
+       ds->indexes = safe_malloc0( ds->numIndexes * sizeof( *ds->indexes ) );
 
        /* set verts */
        VectorSet( ds->verts[ 0 ].xyz, fogMins[ 0 ], fogMins[ 1 ], fogMins[ 2 ] );
index 042c547a613eb4e22900b08810312e64b54e99d7..da8e71f7b3454c4c7d59223711706edb535c7c51 100644 (file)
@@ -301,8 +301,7 @@ void Foliage( mapDrawSurface_t *src ){
                        ds->fogNum = src->fogNum;
 
                        /* add a drawvert for every instance */
-                       verts = safe_malloc( ( ds->numVerts + ds->numFoliageInstances ) * sizeof( *verts ) );
-                       memset( verts, 0, ( ds->numVerts + ds->numFoliageInstances ) * sizeof( *verts ) );
+                       verts = safe_malloc0( ( ds->numVerts + ds->numFoliageInstances ) * sizeof( *verts ) );
                        memcpy( verts, ds->verts, ds->numVerts * sizeof( *verts ) );
                        free( ds->verts );
                        ds->verts = verts;
index 145e1961cc7ee683fcd89814fdddcbc6e61ec6ad..2cd6f0374e8b2aea6189facca07a1dcaf7ae7e7b 100644 (file)
@@ -656,6 +656,7 @@ void FanFaceSurface( mapDrawSurface_t *ds ){
 
        /* add a new vertex at the beginning of the surface */
        verts = safe_malloc( ( ds->numVerts + 1 ) * sizeof( bspDrawVert_t ) );
+       /* beware to only zero the new vertexi at the beginning, nor more! */
        memset( verts, 0, sizeof( bspDrawVert_t ) );
        memcpy( &verts[ 1 ], ds->verts, ds->numVerts * sizeof( bspDrawVert_t ) );
        free( ds->verts );
@@ -1201,13 +1202,11 @@ void SmoothMetaTriangles( void ){
        Sys_FPrintf( SYS_VRB, "--- SmoothMetaTriangles ---\n" );
 
        /* allocate shade angle table */
-       shadeAngles = safe_malloc( numMetaVerts * sizeof( float ) );
-       memset( shadeAngles, 0, numMetaVerts * sizeof( float ) );
+       shadeAngles = safe_malloc0( numMetaVerts * sizeof( float ) );
 
        /* allocate smoothed table */
        cs = ( numMetaVerts / 8 ) + 1;
-       smoothed = safe_malloc( cs );
-       memset( smoothed, 0, cs );
+       smoothed = safe_malloc0( cs );
 
        /* set default shade angle */
        defaultShadeAngle = DEG2RAD( npDegrees );
index bd33c4967b5d2144c71e8ffba388e85827b72747..ef05a3dcbea499414c2eebeb50fa4fa13f23eb3f 100644 (file)
@@ -66,8 +66,7 @@ fixedWinding_t *NewFixedWinding( int points ){
        }
 
        size = (int)( (size_t)( (fixedWinding_t *)0 )->points[points] );
-       w = safe_malloc( size );
-       memset( w, 0, size );
+       w = safe_malloc0( size );
 
        return w;
 }
@@ -936,11 +935,9 @@ void LoadPortals( char *name ){
        portallongs = portalbytes / sizeof( long );
 
        // each file portal is split into two memory portals
-       portals = safe_malloc( 2 * numportals * sizeof( vportal_t ) );
-       memset( portals, 0, 2 * numportals * sizeof( vportal_t ) );
+       portals = safe_malloc0( 2 * numportals * sizeof( vportal_t ) );
 
-       leafs = safe_malloc( portalclusters * sizeof( leaf_t ) );
-       memset( leafs, 0, portalclusters * sizeof( leaf_t ) );
+       leafs = safe_malloc0( portalclusters * sizeof( leaf_t ) );
 
        for ( i = 0; i < portalclusters; i++ )
                leafs[i].merged = -1;
@@ -1036,11 +1033,9 @@ void LoadPortals( char *name ){
 
        }
 
-       faces = safe_malloc( 2 * numfaces * sizeof( vportal_t ) );
-       memset( faces, 0, 2 * numfaces * sizeof( vportal_t ) );
+       faces = safe_malloc0( 2 * numfaces * sizeof( vportal_t ) );
 
-       faceleafs = safe_malloc( portalclusters * sizeof( leaf_t ) );
-       memset( faceleafs, 0, portalclusters * sizeof( leaf_t ) );
+       faceleafs = safe_malloc0( portalclusters * sizeof( leaf_t ) );
 
        for ( i = 0, p = faces; i < numfaces; i++ )
        {
index 5a7ffd92de65c6ed8cc77889b3a22e07e76aa666..3366e5df196e04569e1cb8e9c2f002e491fe749f 100644 (file)
@@ -1364,8 +1364,7 @@ void CreatePassages( int portalnum ){
                        continue;
                }
 
-               passage = (passage_t *) safe_malloc( sizeof( passage_t ) + portalbytes );
-               memset( passage, 0, sizeof( passage_t ) + portalbytes );
+               passage = (passage_t *) safe_malloc0( sizeof( passage_t ) + portalbytes );
                numseperators = AddSeperators( portal->winding, target->winding, qfalse, seperators, MAX_SEPERATORS * 2 );
                numseperators += AddSeperators( target->winding, portal->winding, qtrue, &seperators[numseperators], MAX_SEPERATORS * 2 - numseperators );
 
@@ -1585,14 +1584,11 @@ void BasePortalVis( int portalnum ){
                return;
        }
 
-       p->portalfront = safe_malloc( portalbytes );
-       memset( p->portalfront, 0, portalbytes );
+       p->portalfront = safe_malloc0( portalbytes );
 
-       p->portalflood = safe_malloc( portalbytes );
-       memset( p->portalflood, 0, portalbytes );
+       p->portalflood = safe_malloc0( portalbytes );
 
-       p->portalvis = safe_malloc( portalbytes );
-       memset( p->portalvis, 0, portalbytes );
+       p->portalvis = safe_malloc0( portalbytes );
 
        for ( j = 0, tp = portals ; j < numportals * 2 ; j++, tp++ )
        {