]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
Make ubsan happy
authoruis <uis9936@gmail.com>
Sat, 23 Dec 2023 21:26:08 +0000 (00:26 +0300)
committeruis <uis9936@gmail.com>
Wed, 27 Dec 2023 00:46:11 +0000 (03:46 +0300)
libs/picomodel/pm_md3.c
tools/quake3/q3map2/bspfile_ibsp.c
tools/quake3/q3map2/light.c

index 1b93c7b4d93b2fe875638332fc32510df88a2cda..0540c54ea0cfe3f45b78aee1aeebdf1f1c3056e7 100644 (file)
@@ -149,7 +149,7 @@ static int _md3_canload( PM_PARAMS_CANLOAD ){
        md3 = (const md3_t*) buffer;
 
        /* check md3 magic */
-       if ( *( (const int*) md3->magic ) != *( (const int*) MD3_MAGIC ) ) {
+       if ( memcmp( md3->magic, MD3_MAGIC, 4 ) != 0 ) {
                return PICO_PMV_ERROR_IDENT;
        }
 
@@ -199,7 +199,7 @@ static picoModel_t *_md3_load( PM_PARAMS_LOAD ){
        md3 = (md3_t*) bb;
 
        /* check ident and version */
-       if ( *( (int*) md3->magic ) != *( (int*) MD3_MAGIC ) || _pico_little_long( md3->version ) != MD3_VERSION ) {
+       if ( memcmp( md3->magic, MD3_MAGIC, 4 ) != 0 || _pico_little_long( md3->version ) != MD3_VERSION ) {
                /* not an md3 file (todo: set error) */
                _pico_free( bb0 );
                return NULL;
index 433d4457d220b41afe8593ef367d966c3cad14a1..d4c7e1cf3d09461af30f4a65908ebdea30a3fcbf 100644 (file)
@@ -459,7 +459,7 @@ void LoadIBSPFile( const char *filename ){
        SwapBlock( (int*) ( (byte*) header + sizeof( int ) ), sizeof( *header ) - sizeof( int ) );
 
        /* make sure it matches the format we're trying to load */
-       if ( force == qfalse && *( (int*) header->ident ) != *( (int*) game->bspIdent ) ) {
+       if ( force == qfalse && memcmp( header->ident, game->bspIdent, 4 ) != 0 ) {
                Error( "%s is not a %s file", filename, game->bspIdent );
        }
        if ( force == qfalse && header->version != game->bspVersion ) {
@@ -568,7 +568,7 @@ void WriteIBSPFile( const char *filename ){
        //%     Swapfile();
 
        /* set up header */
-       *( (int*) (bspHeader_t*) header->ident ) = *( (int*) game->bspIdent );
+       memcpy(header->ident, game->bspIdent, 4);
        header->version = LittleLong( game->bspVersion );
 
        /* write initial header */
@@ -577,7 +577,7 @@ void WriteIBSPFile( const char *filename ){
 
        /* add marker lump */
        const char marker[] = "I LOVE MY Q3MAP2";
-       AddLump( file, header, 0, marker, strlen( marker ) + 1 );
+       AddLump( file, (bspHeader_t*) header, 0, marker, strlen( marker ) + 1 );
 
        /* add lumps */
        AddLump( file, (bspHeader_t*) header, LUMP_SHADERS, bspShaders, numBSPShaders * sizeof( bspShader_t ) );
index cff40a8590278320a707aaaad1bd40fbb0142764..26b2a347bfc9d335acd3a6dc50bfbdb495ca46c4 100644 (file)
@@ -1874,11 +1874,12 @@ void SetupGrid( void ){
        /* clear lightgrid */
        for ( i = 0; i < numRawGridPoints; i++ )
        {
-               VectorCopy( ambientColor, rawGridPoints[ i ].ambient[ j ] );
+               VectorCopy( ambientColor, rawGridPoints[ i ].ambient[ 0 ] );
                rawGridPoints[ i ].styles[ 0 ] = LS_NORMAL;
                bspGridPoints[ i ].styles[ 0 ] = LS_NORMAL;
                for ( j = 1; j < MAX_LIGHTMAPS; j++ )
                {
+                       VectorCopy( ambientColor, rawGridPoints[ i ].ambient[ j ] );
                        rawGridPoints[ i ].styles[ j ] = LS_NONE;
                        bspGridPoints[ i ].styles[ j ] = LS_NONE;
                }