engine: fix strict aliasing issues found by an old armv7hf compiler

This commit is contained in:
mittorn 2023-10-21 18:56:30 +03:00 committed by Alibek Omarov
parent 2ecbe5b67e
commit b949da291e
5 changed files with 18 additions and 9 deletions

View File

@ -2247,7 +2247,8 @@ void CL_ReadNetMessage( void )
while( CL_GetMessage( net_message_buffer, &curSize ))
{
if( cls.legacymode && *((int *)&net_message_buffer) == 0xFFFFFFFE )
const int split_header = 0xFFFFFFFE;
if( cls.legacymode && !memcmp( &split_header, net_message_buffer, sizeof( split_header )))
// Will rewrite existing packet by merged
if( !NetSplit_GetLong( &cls.netchan.netsplit, &net_from, net_message_buffer, &curSize ) )
continue;

View File

@ -1534,7 +1534,7 @@ void CL_SendConsistencyInfo( sizebuf_t *msg )
{
case force_exactfile:
MD5_HashFile( md5, filename, NULL );
pc->value = *(int *)md5;
memcpy( &pc->value, md5, sizeof( pc->value ));
if( user_changed_diskfile )
MSG_WriteUBitLong( msg, 0, 32 );

View File

@ -284,8 +284,10 @@ int Image_ComparePalette( const byte *pal )
void Image_SetPalette( const byte *pal, uint *d_table )
{
byte rgba[4];
uint uirgba; // TODO: palette looks byte-swapped on big-endian
int i;
// setup palette
switch( image.d_rendermode )
{
@ -296,7 +298,8 @@ void Image_SetPalette( const byte *pal, uint *d_table )
rgba[1] = pal[i*3+1];
rgba[2] = pal[i*3+2];
rgba[3] = 0xFF;
d_table[i] = *(uint *)rgba;
memcpy( &uirgba, rgba, sizeof( uirgba ));
d_table[i] = uirgba;
}
break;
case LUMP_GRADIENT:
@ -306,7 +309,8 @@ void Image_SetPalette( const byte *pal, uint *d_table )
rgba[1] = pal[766];
rgba[2] = pal[767];
rgba[3] = i;
d_table[i] = *(uint *)rgba;
memcpy( &uirgba, rgba, sizeof( uirgba ));
d_table[i] = uirgba;
}
break;
case LUMP_MASKED:
@ -316,7 +320,8 @@ void Image_SetPalette( const byte *pal, uint *d_table )
rgba[1] = pal[i*3+1];
rgba[2] = pal[i*3+2];
rgba[3] = 0xFF;
d_table[i] = *(uint *)rgba;
memcpy( &uirgba, rgba, sizeof( uirgba ));
d_table[i] = uirgba;
}
d_table[255] = 0;
break;
@ -327,7 +332,8 @@ void Image_SetPalette( const byte *pal, uint *d_table )
rgba[1] = pal[i*4+1];
rgba[2] = pal[i*4+2];
rgba[3] = pal[i*4+3];
d_table[i] = *(uint *)rgba;
memcpy( &uirgba, rgba, sizeof( uirgba ));
d_table[i] = uirgba;
}
break;
}

View File

@ -273,8 +273,10 @@ static void NET_NetadrToSockadr( netadr_t *a, struct sockaddr_storage *s )
}
else if( a->type == NA_IP )
{
uint32_t ip;
((struct sockaddr_in *)s)->sin_family = AF_INET;
((struct sockaddr_in *)s)->sin_addr.s_addr = *(uint32_t *)&a->ip;
memcpy( &ip, &a->ip, sizeof( ip ));
((struct sockaddr_in *)s)->sin_addr.s_addr = ip;
((struct sockaddr_in *)s)->sin_port = a->port;
}
else if( a->type6 == NA_IP6 )
@ -314,7 +316,7 @@ static void NET_SockadrToNetadr( const struct sockaddr_storage *s, netadr_t *a )
if( s->ss_family == AF_INET )
{
a->type = NA_IP;
*(int *)&a->ip = ((struct sockaddr_in *)s)->sin_addr.s_addr;
memcpy( &a->ip, &((struct sockaddr_in *)s)->sin_addr.s_addr, sizeof( uint32_t ));
a->port = ((struct sockaddr_in *)s)->sin_port;
}
else if( s->ss_family == AF_INET6 )

View File

@ -122,7 +122,7 @@ void SV_ParseConsistencyResponse( sv_client_t *cl, sizebuf_t *msg )
value = MSG_ReadUBitLong( msg, 32 );
// will be compare only first 4 bytes
if( value != *(int *)r->rgucMD5_hash )
if( memcmp( &value , r->rgucMD5_hash, 4 ))
badresindex = idx + 1;
}
else