Fix a bunch of bugs

This commit is contained in:
Edoardo Morandi 2020-10-30 21:57:25 +01:00
parent d4fc21e641
commit 6612ae497e
6 changed files with 28 additions and 23 deletions

View file

@ -1707,7 +1707,7 @@ bool idGameLocal::InitFromSaveGame( const char *mapName, idRenderWorld *renderWo
if ( !InhibitEntitySpawn( mapEnt->epairs ) ) { if ( !InhibitEntitySpawn( mapEnt->epairs ) ) {
CacheDictionaryMedia( &mapEnt->epairs ); CacheDictionaryMedia( &mapEnt->epairs );
const char *classname = mapEnt->epairs.GetString( "classname" ); const char *classname = mapEnt->epairs.GetString( "classname" );
if ( classname != '\0' ) { if ( *classname != '\0' ) {
FindEntityDef( classname, false ); FindEntityDef( classname, false );
} }
} }
@ -2148,7 +2148,7 @@ void idGameLocal::GetShakeSounds( const idDict *dict ) {
idStr soundName; idStr soundName;
soundShaderName = dict->GetString( "s_shader" ); soundShaderName = dict->GetString( "s_shader" );
if ( soundShaderName != '\0' && dict->GetFloat( "s_shakes" ) != 0.0f ) { if ( *soundShaderName != '\0' && dict->GetFloat( "s_shakes" ) != 0.0f ) {
soundShader = declManager->FindSound( soundShaderName ); soundShader = declManager->FindSound( soundShaderName );
for ( int i = 0; i < soundShader->GetNumSounds(); i++ ) { for ( int i = 0; i < soundShader->GetNumSounds(); i++ ) {

View file

@ -875,20 +875,20 @@ idPVS::Shutdown
*/ */
void idPVS::Shutdown( void ) { void idPVS::Shutdown( void ) {
if ( connectedAreas ) { if ( connectedAreas ) {
delete connectedAreas; delete[] connectedAreas;
connectedAreas = NULL; connectedAreas = NULL;
} }
if ( areaQueue ) { if ( areaQueue ) {
delete areaQueue; delete[] areaQueue;
areaQueue = NULL; areaQueue = NULL;
} }
if ( areaPVS ) { if ( areaPVS ) {
delete areaPVS; delete[] areaPVS;
areaPVS = NULL; areaPVS = NULL;
} }
if ( currentPVS ) { if ( currentPVS ) {
for ( int i = 0; i < MAX_CURRENT_PVS; i++ ) { for ( int i = 0; i < MAX_CURRENT_PVS; i++ ) {
delete currentPVS[i].pvs; delete[] currentPVS[i].pvs;
currentPVS[i].pvs = NULL; currentPVS[i].pvs = NULL;
} }
} }

View file

@ -583,19 +583,20 @@ static void LoadTGA( const char *name, byte **pic, int *width, int *height, ID_T
targa_header.colormap_type = *buf_p++; targa_header.colormap_type = *buf_p++;
targa_header.image_type = *buf_p++; targa_header.image_type = *buf_p++;
targa_header.colormap_index = LittleShort ( *(short *)buf_p ); auto const get_little_short = [&buf_p]() {
buf_p += 2; short tmp;
targa_header.colormap_length = LittleShort ( *(short *)buf_p ); memcpy( &tmp, buf_p, sizeof( short ) );
short little_short = LittleShort ( tmp );
buf_p += 2; buf_p += 2;
return little_short;
};
targa_header.colormap_index = get_little_short();
targa_header.colormap_length = get_little_short();
targa_header.colormap_size = *buf_p++; targa_header.colormap_size = *buf_p++;
targa_header.x_origin = LittleShort ( *(short *)buf_p ); targa_header.x_origin = get_little_short();
buf_p += 2; targa_header.y_origin = get_little_short();
targa_header.y_origin = LittleShort ( *(short *)buf_p ); targa_header.width = get_little_short();
buf_p += 2; targa_header.height = get_little_short();
targa_header.width = LittleShort ( *(short *)buf_p );
buf_p += 2;
targa_header.height = LittleShort ( *(short *)buf_p );
buf_p += 2;
targa_header.pixel_size = *buf_p++; targa_header.pixel_size = *buf_p++;
targa_header.attributes = *buf_p++; targa_header.attributes = *buf_p++;

View file

@ -144,7 +144,7 @@ const char *Sys_EXEPath( void ) {
len = readlink( linkpath.c_str(), buf, sizeof( buf ) ); len = readlink( linkpath.c_str(), buf, sizeof( buf ) );
if ( len == -1 ) { if ( len == -1 ) {
Sys_Printf("couldn't stat exe path link %s\n", linkpath.c_str()); Sys_Printf("couldn't stat exe path link %s\n", linkpath.c_str());
buf[ len ] = '\0'; buf[ 0 ] = '\0';
} }
return buf; return buf;
} }

View file

@ -42,7 +42,7 @@ public:
int GetMixBufferSize( void ) { return 0; } int GetMixBufferSize( void ) { return 0; }
int GetNumberOfSpeakers( void ) { int GetNumberOfSpeakers( void ) {
idSoundSystemLocal::s_numberOfSpeakers.GetInteger(); return idSoundSystemLocal::s_numberOfSpeakers.GetInteger();
} }
// doesn't support write API // doesn't support write API

View file

@ -348,7 +348,9 @@ void Sys_InitNetworking(void)
if ( ifr->ifr_addr.sa_family != AF_INET ) { if ( ifr->ifr_addr.sa_family != AF_INET ) {
common->Printf( "not AF_INET\n" ); common->Printf( "not AF_INET\n" );
} else { } else {
ip = ntohl( *( unsigned long *)&ifr->ifr_addr.sa_data[2] ); unsigned long raw_ip;
memcpy( &raw_ip, &ifr->ifr_addr.sa_data[2], sizeof(unsigned long) );
ip = ntohl( raw_ip );
if ( ip == INADDR_LOOPBACK ) { if ( ip == INADDR_LOOPBACK ) {
common->Printf( "loopback\n" ); common->Printf( "loopback\n" );
} else { } else {
@ -361,7 +363,9 @@ void Sys_InitNetworking(void)
if ( ioctl( s, SIOCGIFNETMASK, ifr ) < 0 ) { if ( ioctl( s, SIOCGIFNETMASK, ifr ) < 0 ) {
common->Printf( " SIOCGIFNETMASK failed: %s\n", strerror( errno ) ); common->Printf( " SIOCGIFNETMASK failed: %s\n", strerror( errno ) );
} else { } else {
mask = ntohl( *( unsigned long *)&ifr->ifr_addr.sa_data[2] ); unsigned long raw_mask;
memcpy( &raw_mask, &ifr->ifr_addr.sa_data[2], sizeof(unsigned long) );
mask = ntohl( raw_mask );
if ( ip != INADDR_LOOPBACK ) { if ( ip != INADDR_LOOPBACK ) {
common->Printf( "/%d.%d.%d.%d\n", common->Printf( "/%d.%d.%d.%d\n",
(unsigned char)ifr->ifr_addr.sa_data[2], (unsigned char)ifr->ifr_addr.sa_data[2],