]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/picomodel/pm_md3.c
q3map2 is now waring free
[xonotic/netradiant.git] / libs / picomodel / pm_md3.c
index 55022b287030b3ea47feb6d895a8934c7b7a76f9..b22704dace85b32592d28997e712ca7a34d00970 100644 (file)
@@ -145,21 +145,18 @@ by one structure only.
 
 static int _md3_canload( PM_PARAMS_CANLOAD )
 {
-       md3_t   *md3;
+       const md3_t     *md3;
        
 
-       /* to keep the compiler happy */
-       *fileName = *fileName;
-       
        /* sanity check */
-       if( bufSize < ( sizeof( *md3 ) * 2) )
+       if( (size_t) bufSize < ( sizeof( *md3 ) * 2) )
                return PICO_PMV_ERROR_SIZE;
        
        /* set as md3 */
-       md3     = (md3_t*) buffer;
+       md3     = (const md3_t*) buffer;
        
        /* check md3 magic */
-       if( *((int*) md3->magic) != *((int*) MD3_MAGIC) ) 
+       if( *((const int*) md3->magic) != *((const int*) MD3_MAGIC) ) 
                return PICO_PMV_ERROR_IDENT;
        
        /* check md3 version */
@@ -180,7 +177,7 @@ loads a quake3 arena md3 model file.
 static picoModel_t *_md3_load( PM_PARAMS_LOAD )
 {
        int                             i, j;
-       picoByte_t              *bb;
+       picoByte_t              *bb, *bb0;
        md3_t                   *md3;
        md3Surface_t    *surface;
        md3Shader_t             *shader;
@@ -204,13 +201,15 @@ static picoModel_t *_md3_load( PM_PARAMS_LOAD )
 
 
        /* set as md3 */
-       bb = (picoByte_t*) buffer;
-       md3     = (md3_t*) buffer;
+       bb0 = bb = (picoByte_t*) _pico_alloc(bufSize);
+       memcpy(bb, buffer, bufSize);
+       md3     = (md3_t*) bb;
        
        /* check ident and version */
        if( *((int*) md3->magic) != *((int*) MD3_MAGIC) || _pico_little_long( md3->version ) != MD3_VERSION )
        {
                /* not an md3 file (todo: set error) */
+               _pico_free(bb0);
                return NULL;
        }
        
@@ -229,12 +228,14 @@ static picoModel_t *_md3_load( PM_PARAMS_LOAD )
        if( md3->numFrames < 1 )
        {
                _pico_printf( PICO_ERROR, "MD3 with 0 frames" );
+               _pico_free(bb0);
                return NULL;
        }
        
        if( frameNum < 0 || frameNum >= md3->numFrames )
        {
                _pico_printf( PICO_ERROR, "Invalid or out-of-range MD3 frame specified" );
+               _pico_free(bb0);
                return NULL;
        }
        
@@ -308,6 +309,7 @@ static picoModel_t *_md3_load( PM_PARAMS_LOAD )
        if( picoModel == NULL )
        {
                _pico_printf( PICO_ERROR, "Unable to allocate a new model" );
+               _pico_free(bb0);
                return NULL;
        }
        
@@ -329,6 +331,7 @@ static picoModel_t *_md3_load( PM_PARAMS_LOAD )
                {
                        _pico_printf( PICO_ERROR, "Unable to allocate a new model surface" );
                        PicoFreeModel( picoModel ); /* sea */
+                       _pico_free(bb0);
                        return NULL;
                }
                
@@ -344,6 +347,7 @@ static picoModel_t *_md3_load( PM_PARAMS_LOAD )
                {
                        _pico_printf( PICO_ERROR, "Unable to allocate a new model shader" );
                        PicoFreeModel( picoModel );
+                       _pico_free(bb0);
                        return NULL;
                }
                
@@ -403,6 +407,7 @@ static picoModel_t *_md3_load( PM_PARAMS_LOAD )
        }
        
        /* return the new pico model */
+       _pico_free(bb0);
        return picoModel;
 }