From 09a26e315509164c7664401051e8a2b38f57a026 Mon Sep 17 00:00:00 2001 From: Sergeant_Kolja Date: Sun, 27 May 2007 12:34:43 +0000 Subject: [PATCH] in ReadInAttachmentComboMergeStats() added a missing fclose plus a missing XML_free in Items.cpp added unfriendly code to trace + stop the game when pObj is corrupted. (the corruption comes from somewhere outside the destructed foo!) git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@900 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Items.cpp | 10 +++++++++- Tactical/XML_ComboMergeInfo.cpp | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Tactical/Items.cpp b/Tactical/Items.cpp index 541923f00..3e043efd2 100644 --- a/Tactical/Items.cpp +++ b/Tactical/Items.cpp @@ -6556,8 +6556,16 @@ INT16 GetRateOfFireBonus( OBJECTTYPE * pObj ) INT8 bLoop; INT16 bns=0; + if( (MAXITEMS <= pObj->usItem) || (MAXITEMS <= pObj->usGunAmmoItem) ) + { + DebugMsg(TOPIC_JA2, DBG_LEVEL_1, String("GetRateOfFireBonus would crash: pObj->usItem=%d or pObj->usGunAmmoItem=%d ist higher than max %d", pObj->usItem, pObj->usGunAmmoItem, MAXITEMS )); + ScreenMsg( MSG_FONT_RED, MSG_DEBUG, L"GetRateOfFireBonus would crash: pObj->usItem=%d or pObj->usGunAmmoItem=%d ist higher than max %d", pObj->usItem, pObj->usGunAmmoItem, MAXITEMS ); + AssertMsg( 0, "GetRateOfFireBonus would crash" ); + return 0; /* cannot calculate Bonus, this only happens sometimes in FULLSCREEN */ + } + bns = BonusReduceMore( Item[pObj->usItem].rateoffirebonus, pObj->bStatus[0] ); - bns += Item[pObj->usGunAmmoItem].rateoffirebonus ; + bns += Item[pObj->usGunAmmoItem].rateoffirebonus; for (bLoop = 0; bLoop < MAX_ATTACHMENTS; bLoop++) { diff --git a/Tactical/XML_ComboMergeInfo.cpp b/Tactical/XML_ComboMergeInfo.cpp index baeec7b66..31445319c 100644 --- a/Tactical/XML_ComboMergeInfo.cpp +++ b/Tactical/XML_ComboMergeInfo.cpp @@ -193,6 +193,7 @@ BOOLEAN ReadInAttachmentComboMergeStats(STR fileName) if ( !FileRead( hFile, lpcBuffer, uiFSize, &uiBytesRead ) ) { MemFree(lpcBuffer); + FileClose( hFile ); /* added, Sgt. Kolja */ return( FALSE ); } @@ -220,6 +221,7 @@ BOOLEAN ReadInAttachmentComboMergeStats(STR fileName) LiveMessage(errorBuf); MemFree(lpcBuffer); + XML_ParserFree(parser); /* added, Sgt. Kolja */ return FALSE; }