From 9d5ac74a28985215ce34f851076d84d0d3b50f1d Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sun, 13 May 2012 14:40:11 +0200 Subject: [PATCH 1/3] Fix several bugs from iodoom3 bugtracker rhyskidd@gmail.com found them (with PVS studio IIRC), reported them and posted patches. Some of the patches were incorrect so I rewrote them. --- neo/game/Game_local.cpp | 8 +++++--- neo/renderer/Model_liquid.cpp | 2 -- neo/tools/radiant/XYWnd.cpp | 2 +- neo/tools/radiant/splines.cpp | 4 ---- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/neo/game/Game_local.cpp b/neo/game/Game_local.cpp index 3b99f75d..65216457 100644 --- a/neo/game/Game_local.cpp +++ b/neo/game/Game_local.cpp @@ -1257,8 +1257,8 @@ bool idGameLocal::InitFromSaveGame( const char *mapName, idRenderWorld *renderWo if ( !InhibitEntitySpawn( mapEnt->epairs ) ) { CacheDictionaryMedia( &mapEnt->epairs ); - const char *classname = mapEnt->epairs.GetString( "classname" ); - if ( classname != '\0' ) { + const char *classname; + if ( mapEnt->epairs.GetString( "classname", "", &classname ) ) { FindEntityDef( classname, false ); } } @@ -1627,7 +1627,9 @@ void idGameLocal::GetShakeSounds( const idDict *dict ) { idStr soundName; soundShaderName = dict->GetString( "s_shader" ); - if ( soundShaderName != '\0' && dict->GetFloat( "s_shakes" ) != 0.0f ) { + if ( dict->GetString( "s_shader", "", &soundShaderName ) + && dict->GetFloat( "s_shakes" ) != 0.0f ) + { soundShader = declManager->FindSound( soundShaderName ); for ( int i = 0; i < soundShader->GetNumSounds(); i++ ) { diff --git a/neo/renderer/Model_liquid.cpp b/neo/renderer/Model_liquid.cpp index e5d3daf2..ff7fb87b 100644 --- a/neo/renderer/Model_liquid.cpp +++ b/neo/renderer/Model_liquid.cpp @@ -399,8 +399,6 @@ void idRenderModelLiquid::InitFromFile( const char *fileName ) { } else if ( !token.Icmp( "shader" ) ) { parser.ReadToken( &token ); shader = declManager->FindMaterial( token ); - } else if ( !token.Icmp( "seed" ) ) { - seed = parser.ParseInt(); } else if ( !token.Icmp( "update_rate" ) ) { rate = parser.ParseFloat(); if ( ( rate <= 0.0f ) || ( rate > 60.0f ) ) { diff --git a/neo/tools/radiant/XYWnd.cpp b/neo/tools/radiant/XYWnd.cpp index 7d58e994..8911d205 100644 --- a/neo/tools/radiant/XYWnd.cpp +++ b/neo/tools/radiant/XYWnd.cpp @@ -4285,7 +4285,7 @@ void CXYWnd::Paste() int nLen = g_Clipboard.GetLength(); char *pBuffer = new char[nLen + 1]; - memset(pBuffer, 0, sizeof(pBuffer)); + memset(pBuffer, 0, sizeof(*pBuffer) * (nLen + 1)); g_Clipboard.Read(pBuffer, nLen); pBuffer[nLen] = '\0'; Map_ImportBuffer(pBuffer, !(GetAsyncKeyState(VK_SHIFT) & 0x8000)); diff --git a/neo/tools/radiant/splines.cpp b/neo/tools/radiant/splines.cpp index babcd531..9a93ea08 100644 --- a/neo/tools/radiant/splines.cpp +++ b/neo/tools/radiant/splines.cpp @@ -1565,10 +1565,6 @@ bool idCameraPosition::parseToken( const idStr &key, idParser *src ) { name = token; return true; } - else if ( !key.Icmp( "time" ) ) { - time = src->ParseInt(); - return true; - } else { src->Error( "unknown camera position key: %s", key.c_str() ); return false; From 4ab609f3960c1a666057b64efe81eb9fe03a3985 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sun, 13 May 2012 15:06:59 +0200 Subject: [PATCH 2/3] (Hopefully) fix call to LittleRevBytes in idGameLocal::ServerWriteSnapshot() Makes more sense than before, but TBH I'm not entirely sure what this is supposed to do. --- neo/d3xp/Game_network.cpp | 10 +++++++++- neo/game/Game_network.cpp | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/neo/d3xp/Game_network.cpp b/neo/d3xp/Game_network.cpp index d65be3d9..ab0dc861 100644 --- a/neo/d3xp/Game_network.cpp +++ b/neo/d3xp/Game_network.cpp @@ -702,8 +702,16 @@ void idGameLocal::ServerWriteSnapshot( int clientNum, int sequence, idBitMsg &ms WriteGameStateToSnapshot( deltaMsg ); // copy the client PVS string + // copies 4 bytes (== one int)?! memcpy( clientInPVS, snapshot->pvs, ( numPVSClients + 7 ) >> 3 ); - LittleRevBytes( clientInPVS, sizeof( int ), sizeof( clientInPVS ) / sizeof ( int ) ); + // FIXME: fishy. + // byte clientInPVS[MAX_ASYNC_CLIENTS >> 3]; + // numPVSClients == MAX_ASYNC_CLIENTS + // I think the orig code only "works" because it's a no-op on little endian architectures (like x86) + // orig code: LittleRevBytes( clientInPVS, sizeof( int ), sizeof( clientInPVS ) / sizeof ( int ) ); + // sizeof( clientInPVS ) ?! (== sizeof(size_t)) + // not sure if the replacement is 100% correct, though + LittleRevBytes( clientInPVS, sizeof( int ), (( numPVSClients + 7 ) >> 3) / sizeof ( int ) ); } /* diff --git a/neo/game/Game_network.cpp b/neo/game/Game_network.cpp index 0a1b07a0..8cbda041 100644 --- a/neo/game/Game_network.cpp +++ b/neo/game/Game_network.cpp @@ -688,8 +688,16 @@ void idGameLocal::ServerWriteSnapshot( int clientNum, int sequence, idBitMsg &ms WriteGameStateToSnapshot( deltaMsg ); // copy the client PVS string + // copies 4 bytes (== one int)?! memcpy( clientInPVS, snapshot->pvs, ( numPVSClients + 7 ) >> 3 ); - LittleRevBytes( clientInPVS, sizeof( int ), sizeof( clientInPVS ) / sizeof ( int ) ); + // FIXME: fishy. + // byte clientInPVS[MAX_ASYNC_CLIENTS >> 3]; + // numPVSClients == MAX_ASYNC_CLIENTS + // I think the orig code only "works" because it's a no-op on little endian architectures (like x86) + // orig code: LittleRevBytes( clientInPVS, sizeof( int ), sizeof( clientInPVS ) / sizeof ( int ) ); + // sizeof( clientInPVS ) ?! (== sizeof(size_t)) + // not sure if the replacement is 100% correct, though + LittleRevBytes( clientInPVS, sizeof( int ), (( numPVSClients + 7 ) >> 3) / sizeof ( int ) ); } /* From 34a2a07d55a4f7a34adb5de8130a75122fe2172b Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Tue, 22 May 2012 21:48:34 +0200 Subject: [PATCH 3/3] Remove superfluous call to dict->GetString it's called again one line below (this time checking if the key really existed in the dict) I overlooked this in "Fix several bugs from iodoom3 bugtracker" --- neo/game/Game_local.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/neo/game/Game_local.cpp b/neo/game/Game_local.cpp index 65216457..0f9cbae0 100644 --- a/neo/game/Game_local.cpp +++ b/neo/game/Game_local.cpp @@ -1626,7 +1626,6 @@ void idGameLocal::GetShakeSounds( const idDict *dict ) { const char *soundShaderName; idStr soundName; - soundShaderName = dict->GetString( "s_shader" ); if ( dict->GetString( "s_shader", "", &soundShaderName ) && dict->GetFloat( "s_shakes" ) != 0.0f ) {