From f92f70c78d048bbfc238ff6dc9dc33584932c487 Mon Sep 17 00:00:00 2001 From: Flugente Date: Mon, 27 May 2013 20:38:52 +0000 Subject: [PATCH] cleaned up code: various stuff (out-of-bounds, null-pointer, uninitialized vars,...) (by CleaningWoman) git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6101 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Console/Console.cpp | 1 + Laptop/BobbyRGuns.cpp | 4 ++ Laptop/BobbyRMailOrder.cpp | 8 +-- Laptop/CharProfile.cpp | 4 +- Laptop/IMP Attribute Selection.cpp | 2 +- Laptop/IMP Confirm.cpp | 1 + Laptop/IMP Disability Trait.cpp | 2 +- Laptop/IMP Minor Trait.cpp | 2 +- Laptop/XML_Email.cpp | 31 ++++---- Laptop/XML_EncyclopediaLocation.cpp | 16 ++--- Laptop/email.cpp | 2 +- Laptop/finances.cpp | 2 + Laptop/mercs.cpp | 7 +- Multiplayer/client.cpp | 31 ++++---- Multiplayer/server.cpp | 4 ++ Standard Gaming Platform/Font.cpp | 2 +- Standard Gaming Platform/MemMan.cpp | 2 +- Standard Gaming Platform/input.cpp | 14 ++-- Standard Gaming Platform/sgp.cpp | 2 +- Strategic/AI Viewer.cpp | 2 +- Strategic/Assignments.cpp | 4 +- Strategic/Auto Resolve.cpp | 1 + Strategic/LuaInitNPCs.cpp | 4 +- .../Map Screen Interface Map Inventory.cpp | 6 +- Strategic/strategicmap.cpp | 6 +- Tactical/Handle UI.cpp | 18 +---- Tactical/Interface Enhanced.cpp | 6 +- Tactical/Interface Items.cpp | 6 +- Tactical/Overhead.cpp | 2 +- Tactical/Soldier Create.cpp | 16 +++-- Tactical/XML_Drugs.cpp | 2 +- Tactical/XML_Food.cpp | 2 +- Tactical/XML_NewFaceGear.cpp | 2 +- Tactical/XML_SectorLoadscreens.cpp | 12 ++-- Tactical/XML_Vehicles.cpp | 8 +-- TacticalAI/NPC.cpp | 71 ++++++++++--------- TileEngine/Explosion Control.cpp | 4 +- TileEngine/physics.cpp | 2 + XML_Layout_MainMenu.cpp | 5 +- 39 files changed, 167 insertions(+), 149 deletions(-) diff --git a/Console/Console.cpp b/Console/Console.cpp index d66996a7..b642bbd8 100644 --- a/Console/Console.cpp +++ b/Console/Console.cpp @@ -4042,6 +4042,7 @@ void Console::CopyTextToClipboard() { // lock the handle and copy the text to the buffer. wchar_t* pszData = (wchar_t*)::GlobalLock(hglbData); + if (pszData) { int i; for (i = 0; i < nSelRows; ++i) { diff --git a/Laptop/BobbyRGuns.cpp b/Laptop/BobbyRGuns.cpp index 2de56e09..cb02b71b 100644 --- a/Laptop/BobbyRGuns.cpp +++ b/Laptop/BobbyRGuns.cpp @@ -1943,6 +1943,10 @@ BOOLEAN DisplayBigItemImage(UINT16 usIndex, UINT16 PosY) sOffsetX = hPixHandle->p16BPPObject->sOffsetX; sOffsetY = hPixHandle->p16BPPObject->sOffsetY; } + else + { + Assert(false); + } // sCenX = PosX + ( abs( BOBBYR_GRID_PIC_WIDTH - usWidth ) / 2 ); // sCenY = PosY + 8; diff --git a/Laptop/BobbyRMailOrder.cpp b/Laptop/BobbyRMailOrder.cpp index a4e9689d..61709716 100644 --- a/Laptop/BobbyRMailOrder.cpp +++ b/Laptop/BobbyRMailOrder.cpp @@ -1104,7 +1104,7 @@ void DisplayPurchasedItems( BOOLEAN fCalledFromOrderPage, UINT16 usGridX, UINT16 if( pBobbyRayPurchase[i].fUsed ) { LoadBRName(pBobbyRayPurchase[i].usItemIndex,sBack); - swprintf(sText, L"%s %s", "*", sBack); + swprintf(sText, L"%s %s", L"*", sBack); } else LoadBRName(pBobbyRayPurchase[i].usItemIndex,sText); @@ -1309,7 +1309,7 @@ void DisplayShippingCosts( BOOLEAN fCalledFromOrderPage, INT32 iSubTotal, UINT16 while(spi != gShipmentTable[iOrderNum]->ShipmentPackages.end()) { uiPackageWeight += Item[((ShipmentPackageStruct&)*spi).usItemIndex].ubWeight; - spi++; + ++spi; } uiPackageWeight = uiPackageWeight > 20 ? uiPackageWeight : 20; @@ -2883,13 +2883,13 @@ BOOLEAN NewWayOfLoadingBobbyRMailOrdersToSaveGameFile( HWFILE hFile ) { //Allocate memory for the list gpNewBobbyrShipments = (NewBobbyRayOrderStruct *) MemAlloc( sizeof( NewBobbyRayOrderStruct ) * giNumberOfNewBobbyRShipment ); - memset(gpNewBobbyrShipments, 0, (sizeof( NewBobbyRayOrderStruct ) * giNumberOfNewBobbyRShipment) ); - if( gpNewBobbyrShipments == NULL ) + if( gpNewBobbyrShipments == NULL ) { Assert(0); return(FALSE ); } + memset(gpNewBobbyrShipments, 0, (sizeof( NewBobbyRayOrderStruct ) * giNumberOfNewBobbyRShipment) ); //loop through and load all the mail order slots for( iCnt=0; iCnt 1 && iStartingLevel <= 10) { diff --git a/Laptop/IMP Confirm.cpp b/Laptop/IMP Confirm.cpp index 60123383..fb9a4a86 100644 --- a/Laptop/IMP Confirm.cpp +++ b/Laptop/IMP Confirm.cpp @@ -1691,6 +1691,7 @@ void GiveIMPRandomItems( MERCPROFILESTRUCT *pProfile, UINT8 typeIndex ) MakeProfileInvItemAnySlot(pProfile,usItem,100,1); // give ammo for guns + Assert(usItem IMP_DISABILITIES_NUMBER ) + if( uiSkillPressed >= IMP_DISABILITIES_NUMBER ) { Assert( 0 ); return; diff --git a/Laptop/IMP Minor Trait.cpp b/Laptop/IMP Minor Trait.cpp index 7cb882a2..9954ae1f 100644 --- a/Laptop/IMP Minor Trait.cpp +++ b/Laptop/IMP Minor Trait.cpp @@ -321,7 +321,7 @@ void HandleIMPMinorTraitAnswers( UINT32 uiSkillPressed ) } //make sure its a valid skill - if( uiSkillPressed > IMP_SKILL_TRAITS_NEW_NUMBER_MINOR_SKILLS ) + if( uiSkillPressed >= IMP_SKILL_TRAITS_NEW_NUMBER_MINOR_SKILLS ) { Assert( 0 ); return; diff --git a/Laptop/XML_Email.cpp b/Laptop/XML_Email.cpp index 2ef7e1fc..dae5a04e 100644 --- a/Laptop/XML_Email.cpp +++ b/Laptop/XML_Email.cpp @@ -125,22 +125,23 @@ EmailOtherEndElementHandle(void *userData, const XML_Char *name) if (!EmailOther_TextOnly) { wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szSubject, pData->curEmailOther.szSubject); - wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[0], L"1. sdssdsfs dfg fdgd fgffdsf test" ); //pData->curEmailOther.szMessage[0]); - wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[1], L"2. sdssdsfs dfg fgfgffdsf test" ); - wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[2], L"3. sdssdsfsd gdfg fdfgfdg ffdsf test" ); - wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[3], L"4. sdssdsf dgdfg dgsffdsf test" ); - wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[4], L"5. sdssdsfdgdfg dgfd gsffdsf test" ); - wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[5], L"6. sdssdsfsffdsf test" ); - wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[6], L"7. sdssdsfsffdsf test" ); - wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[7], L"8. sdssdsfsfdgdgfgfdsf test" ); - wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[8], L"9. sdssdsfsff dg dfgdg fg dfg dsf test" ); - wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[9], L"10. sdssdsfsfgdsgdfgfdsf test" ); - wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[10], L"11. sdssdsfsff dgdf fgfdg dfgd dsf test" ); - wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[11], L"12. sdssdsfsf dfg dfgf gdfg dsf test" ); - wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[12], L"13. sdssdsfsf dfgdfgdf gdfg gfdsf test" ); + // L"12345678901234567890123456789" <- max lenght (szMessage[30]) + wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[0], L"1. sdssdsfs dfg fdgd fg test" ); //pData-curEmailOther.szMessage[0]); + wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[1], L"2. sdssdsfs dfg fgfgffds test" ); + wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[2], L"3. sdssdsfsd gdfg fdfgsf test" ); + wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[3], L"4. sdssdsf dgdfg dgsfdsf test" ); + wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[4], L"5. sdssdsfdgdfg dgfddsf test" ); + wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[5], L"6. sdssdsfsffdsf test" ); + wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[6], L"7. sdssdsfsffdsf test" ); + wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[7], L"8. sdssdsfsfdgdgfgfdsf test" ); + wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[8], L"9. sdssdsfsff dg gdg dsf test" ); + wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[9], L"10. sdssdsfsfgdsgdfgfdsf test" ); + wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[10], L"11. sdssdsfsff dgfgd dsf test" ); + wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[11], L"12. sdssdsfsf dfgdfg dsf test" ); + wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[12], L"13. sdssdsfsf dfgg gfdsf test" ); wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[13], L"14. sdssdsf dgdf gsffdsf test" ); - wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[14], L"15. sdssdsf dgdf dfg d gdf ffdsf test" ); - wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[15], L"16. sdssdsfs dgdfg fdg dgdfg gffdsf test" ); + wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[14], L"15. sdssdsf dgdf f ffdsf test" ); + wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[15], L"16. sdssdsfs dgdf gffdsf test" ); /* wcscpy(EmailOtherText[pData->curEmailOther.uiIndex].szMessage[1], pData->curEmailOther.szMessage[1]); diff --git a/Laptop/XML_EncyclopediaLocation.cpp b/Laptop/XML_EncyclopediaLocation.cpp index 7af2d969..3a476df8 100644 --- a/Laptop/XML_EncyclopediaLocation.cpp +++ b/Laptop/XML_EncyclopediaLocation.cpp @@ -71,7 +71,7 @@ BOOLEAN bMERC; BOOLEAN LoadEncyclopediaMercBio( UINT8 ubIndex, STR16 pInfoString, STR16 pAddInfo,UINT32 Type ) { - HWFILE hFile; + HWFILE hFile=NULL; UINT32 uiBytesRead; //UINT16 i; UINT32 uiStartSeekAmount; @@ -822,7 +822,7 @@ encyclopediaLocationEndElementHandle(void *userData, const XML_Char *name) else { strncpy(pData->curEncyclopediaData.szFile,pData->szCharData,MAX_ENCYCLOPEDIA_CHARS); - pData->curEncyclopediaData.szFile[MAX_ENCYCLOPEDIA_CHARS] = '\0'; + pData->curEncyclopediaData.szFile[MAX_ENCYCLOPEDIA_CHARS-1] = '\0'; } for(int i=0;iszCharData),MAX_ENCYCLOPEDIA_CHARS);i++) @@ -841,7 +841,7 @@ encyclopediaLocationEndElementHandle(void *userData, const XML_Char *name) else { strncpy(pData->curEncyclopediaData.szFile2,pData->szCharData,MAX_ENCYCLOPEDIA_CHARS); - pData->curEncyclopediaData.szFile2[MAX_ENCYCLOPEDIA_CHARS] = '\0'; + pData->curEncyclopediaData.szFile2[MAX_ENCYCLOPEDIA_CHARS-1] = '\0'; } for(int i=0;iszCharData),MAX_ENCYCLOPEDIA_CHARS);i++) @@ -860,7 +860,7 @@ encyclopediaLocationEndElementHandle(void *userData, const XML_Char *name) else { strncpy(pData->curEncyclopediaData.szFile3,pData->szCharData,MAX_ENCYCLOPEDIA_CHARS); - pData->curEncyclopediaData.szFile3[MAX_ENCYCLOPEDIA_CHARS] = '\0'; + pData->curEncyclopediaData.szFile3[MAX_ENCYCLOPEDIA_CHARS-1] = '\0'; } for(int i=0;iszCharData),MAX_ENCYCLOPEDIA_CHARS);i++) @@ -879,7 +879,7 @@ encyclopediaLocationEndElementHandle(void *userData, const XML_Char *name) else { strncpy(pData->curEncyclopediaData.szFile4,pData->szCharData,MAX_ENCYCLOPEDIA_CHARS); - pData->curEncyclopediaData.szFile4[MAX_ENCYCLOPEDIA_CHARS] = '\0'; + pData->curEncyclopediaData.szFile4[MAX_ENCYCLOPEDIA_CHARS-1] = '\0'; } for(int i=0;iszCharData),MAX_ENCYCLOPEDIA_CHARS);i++) @@ -972,7 +972,7 @@ encyclopediaLocationEndElementHandle(void *userData, const XML_Char *name) else { strncpy(pData->curEncyclopediaData.BeforeImage,pData->szCharData,MAX_ENCYCLOPEDIA_CHARS); - pData->curEncyclopediaData.BeforeImage[MAX_ENCYCLOPEDIA_CHARS] = '\0'; + pData->curEncyclopediaData.BeforeImage[MAX_ENCYCLOPEDIA_CHARS-1] = '\0'; } for(int i=0;iszCharData),MAX_ENCYCLOPEDIA_CHARS);i++) @@ -990,7 +990,7 @@ encyclopediaLocationEndElementHandle(void *userData, const XML_Char *name) else { strncpy(pData->curEncyclopediaData.AfterImage,pData->szCharData,MAX_ENCYCLOPEDIA_CHARS); - pData->curEncyclopediaData.AfterImage[MAX_ENCYCLOPEDIA_CHARS] = '\0'; + pData->curEncyclopediaData.AfterImage[MAX_ENCYCLOPEDIA_CHARS-1] = '\0'; } for(int i=0;iszCharData),MAX_ENCYCLOPEDIA_CHARS);i++) @@ -1049,7 +1049,7 @@ encyclopediaLocationEndElementHandle(void *userData, const XML_Char *name) else { strncpy(pData->curEncyclopediaData.sSounds,pData->szCharData,MAX_ENCYCLOPEDIA_CHARS); - pData->curEncyclopediaData.sSounds[MAX_ENCYCLOPEDIA_CHARS] = '\0'; + pData->curEncyclopediaData.sSounds[MAX_ENCYCLOPEDIA_CHARS-1] = '\0'; } for(int i=0;iszCharData),MAX_ENCYCLOPEDIA_CHARS);i++) diff --git a/Laptop/email.cpp b/Laptop/email.cpp index fc5ba41f..8fb1a38a 100644 --- a/Laptop/email.cpp +++ b/Laptop/email.cpp @@ -1560,7 +1560,7 @@ void SwapMessages(INT32 iIdA, INT32 iIdB) // wcscpy(pTemp->pSubject,EmailOtherText[pA->usLength].szSubject); else if ( pA->EmailVersion == TYPE_EMAIL_BOBBY_R || pA->EmailVersion == TYPE_EMAIL_BOBBY_R_EMAIL_JA2_EDT ) wcscpy(pTemp->pSubject,pA->pSubject); - else if ( pA->EmailVersion == TYPE_EMAIL_EMAIL_EDT || pA->EmailVersion == TYPE_EMAIL_INSURANCE_COMPANY_EMAIL_JA2_EDT || TYPE_EMAIL_DEAD_MERC_AIM_SITE_EMAIL_JA2_EDT ) + else if ( pA->EmailVersion == TYPE_EMAIL_EMAIL_EDT || pA->EmailVersion == TYPE_EMAIL_INSURANCE_COMPANY_EMAIL_JA2_EDT || pA->EmailVersion == TYPE_EMAIL_DEAD_MERC_AIM_SITE_EMAIL_JA2_EDT ) wcscpy(pTemp->pSubject,pA->pSubject); // pA becomes pB diff --git a/Laptop/finances.cpp b/Laptop/finances.cpp index ea30283f..685b73e8 100644 --- a/Laptop/finances.cpp +++ b/Laptop/finances.cpp @@ -746,6 +746,8 @@ void DrawRecordsColumnHeadersText( void ) void DrawRecordsText( void ) { + Assert(pFinanceListHead); + // draws the text of the records FinanceUnitPtr pCurFinance=pCurrentFinance; FinanceUnitPtr pTempFinance=pFinanceListHead; diff --git a/Laptop/mercs.cpp b/Laptop/mercs.cpp index 13024c05..cceb23b0 100644 --- a/Laptop/mercs.cpp +++ b/Laptop/mercs.cpp @@ -1543,7 +1543,7 @@ void HandleTalkingSpeck() gsSpeckDialogueTextPopUp[0] = '\0'; //Start speck talking - if( gusMercVideoSpeckSpeech != MERC_VIDEO_SPECK_SPEECH_NOT_TALKING || gusMercVideoSpeckSpeech != MERC_VIDEO_SPECK_HAS_TO_TALK_BUT_QUOTE_NOT_CHOSEN_YET ) + if( gusMercVideoSpeckSpeech != MERC_VIDEO_SPECK_SPEECH_NOT_TALKING && gusMercVideoSpeckSpeech != MERC_VIDEO_SPECK_HAS_TO_TALK_BUT_QUOTE_NOT_CHOSEN_YET ) StartSpeckTalking( gusMercVideoSpeckSpeech ); gusMercVideoSpeckSpeech = MERC_VIDEO_SPECK_SPEECH_NOT_TALKING; @@ -2462,7 +2462,7 @@ INT16 GetRandomQuoteThatHasBeenSaidTheLeast( ) if( CanMercQuoteBeSaid( gNumberOfTimesQuoteSaid[cnt].ubQuoteID ) ) { //if this quote has been said less times then the last one - if( gNumberOfTimesQuoteSaid[cnt].uiNumberOfTimesQuoteSaid < gNumberOfTimesQuoteSaid[ sSmallestNumber ].uiNumberOfTimesQuoteSaid ) + if( sSmallestNumber==255 || gNumberOfTimesQuoteSaid[cnt].uiNumberOfTimesQuoteSaid < gNumberOfTimesQuoteSaid[ sSmallestNumber ].uiNumberOfTimesQuoteSaid ) { sSmallestNumber = cnt; } @@ -2688,7 +2688,6 @@ void MakeBiffAwayForCoupleOfDays() BOOLEAN AreAnyOfTheNewMercsAvailable() { - UINT8 i; UINT8 ubMercID; @@ -2696,7 +2695,7 @@ BOOLEAN AreAnyOfTheNewMercsAvailable() return( FALSE ); //for(i=(LARRY_NORMAL-BIFF); i<=LaptopSaveInfo.gubLastMercIndex; i++) - for(i=0; i<=NUM_PROFILES; i++) + for(UINT16 i=0; i<=NUM_PROFILES; i++) { if ( gConditionsForMercAvailability[i].NewMercsAvailable == FALSE && gProfilesMERC[i].ProfilId != 0 ) { diff --git a/Multiplayer/client.cpp b/Multiplayer/client.cpp index d1881e08..a55b61e7 100644 --- a/Multiplayer/client.cpp +++ b/Multiplayer/client.cpp @@ -1736,6 +1736,7 @@ void start_battle ( void ) } //SOLDIERTYPE *pSoldier = MercPtrs[ 0 ]; + Assert(pSoldier); UINT8 ubGroupID = pSoldier->ubGroupID; GROUP *pGroup; @@ -3376,7 +3377,7 @@ void send_disarm_explosive(UINT32 sGridNo, UINT32 uiWorldItem, UINT8 ubID) #ifdef JA2BETAVERSION CHAR tmpMPDbgString[512]; - sprintf(tmpMPDbgString,"MP - send_disarm_explosive ( MPTeam : %i , uiWorldIndex : %i , uiPreRandomIndex : %i , sGridNo : %i )\n",disarm.ubMPTeamIndex, disarm.uiWorldItemIndex , disarm.uiPreRandomIndex ); + sprintf(tmpMPDbgString,"MP - send_disarm_explosive ( MPTeam : %i , uiWorldIndex : %i , uiPreRandomIndex : %i , sGridNo : %i )\n", disarm.ubMPTeamIndex, disarm.uiWorldItemIndex , disarm.uiPreRandomIndex, disarm.sGridNo); MPDebugMsg(tmpMPDbgString); gfMPDebugOutputRandoms = true; #endif @@ -3842,9 +3843,9 @@ void send_death( SOLDIERTYPE *pSoldier ) } SOLDIERTYPE * pAttacker=MercPtrs[ nDeath.attacker_id ]; - INT8 pA_bTeam; + INT8 pA_bTeam=CLIENT_NUM; CHAR16 pA_name[ 10 ]; - INT8 pS_bTeam; + INT8 pS_bTeam=CLIENT_NUM; CHAR16 pS_name[ 10 ]; // OJW - 20081222 @@ -3915,23 +3916,25 @@ void send_death( SOLDIERTYPE *pSoldier ) client->RPC("sendDEATH",(const char*)&nDeath, (int)sizeof(death_struct)*8, HIGH_PRIORITY, RELIABLE, 0, UNASSIGNED_SYSTEM_ADDRESS, true, 0, UNASSIGNED_NETWORK_ID,0); // print kill notice to screen - if (pSoldier->bTeam==1) + if (pSoldier && pSoldier->bTeam==1) ScreenMsg( FONT_YELLOW, MSG_MPSYSTEM, MPClientMessage[67]); else ScreenMsg( FONT_LTGREEN, MSG_MPSYSTEM, MPClientMessage[28],pS_name,(pS_bTeam),client_names[(pS_bTeam-1)],pA_name,(pA_bTeam),client_names[(pA_bTeam-1)] ); #ifdef JA2BETAVERSION - char s_name[10]; - char a_name[10]; - WideCharToMultiByte(CP_UTF8,0,pS_name,-1, s_name,10,NULL,NULL); - WideCharToMultiByte(CP_UTF8,0,pA_name,-1, a_name,10,NULL,NULL); + if (pSoldier) { + char s_name[10]; + char a_name[10]; + WideCharToMultiByte(CP_UTF8,0,pS_name,-1, s_name,10,NULL,NULL); + WideCharToMultiByte(CP_UTF8,0,pA_name,-1, a_name,10,NULL,NULL); - if (pSoldier->bTeam==1) - MPDebugMsg( String ( "MPDEBUG SEND - Enemy AI #%d was killed by ('%s' - %d) (client %d - '%s')\n",nDeath.soldier_id,a_name,nDeath.attacker_id,pA_bTeam,client_names[pA_bTeam-1]) ); - else if (pAttacker->bTeam==1) - MPDebugMsg( String ( "MPDEBUG SEND - '%s' (client %d - '%S') was killed by '%s' (client %d - '%s')\n",s_name,pS_bTeam,client_names[(pS_bTeam-1)],a_name,pA_bTeam,"Queens Army") ); - else - MPDebugMsg( String ( "MPDEBUG SEND - '%s' (client %d - '%S') was killed by '%s' (client %d - '%s')\n",s_name,pS_bTeam,client_names[(pS_bTeam-1)],a_name,pA_bTeam,client_names[(pA_bTeam-1)]) ); + if (pSoldier->bTeam==1) + MPDebugMsg( String ( "MPDEBUG SEND - Enemy AI #%d was killed by ('%s' - %d) (client %d - '%s')\n",nDeath.soldier_id,a_name,nDeath.attacker_id,pA_bTeam,client_names[pA_bTeam-1]) ); + else if (pAttacker->bTeam==1) + MPDebugMsg( String ( "MPDEBUG SEND - '%s' (client %d - '%S') was killed by '%s' (client %d - '%s')\n",s_name,pS_bTeam,client_names[(pS_bTeam-1)],a_name,pA_bTeam,"Queens Army") ); + else + MPDebugMsg( String ( "MPDEBUG SEND - '%s' (client %d - '%S') was killed by '%s' (client %d - '%s')\n",s_name,pS_bTeam,client_names[(pS_bTeam-1)],a_name,pA_bTeam,client_names[(pA_bTeam-1)]) ); + } #endif } diff --git a/Multiplayer/server.cpp b/Multiplayer/server.cpp index 6676855f..c1829415 100644 --- a/Multiplayer/server.cpp +++ b/Multiplayer/server.cpp @@ -238,6 +238,7 @@ void sendHIT(RPCParameters *rpcParameters) else if (team == 0) team = CLIENT_NUM-1; // this case should not be possible, including as a precaution + Assert(team<5); // FIXME gMPPlayerStats[team].hits++; server->RPC("recieveHIT",(const char*)rpcParameters->input, (*rpcParameters).numberOfBitsOfData, HIGH_PRIORITY, RELIABLE, 0, rpcParameters->sender, true, 0, UNASSIGNED_NETWORK_ID,0); @@ -386,6 +387,7 @@ void sendhitSTRUCT(RPCParameters *rpcParameters) else if (team == 0) team = CLIENT_NUM-1; // this case should not be possible, including as a precaution + Assert(team<5); // FIXME gMPPlayerStats[team].misses++; } @@ -410,6 +412,7 @@ void sendhitWINDOW(RPCParameters *rpcParameters) else if (team == 0) team = CLIENT_NUM-1; // this case should not be possible, including as a precaution + Assert(team<5); // FIXME gMPPlayerStats[team].misses++; } @@ -433,6 +436,7 @@ void sendMISS(RPCParameters *rpcParameters) else if (team == 0) team = CLIENT_NUM-1; // this case should not be possible, including as a precaution + Assert(team<5); // FIXME gMPPlayerStats[team].misses++; } diff --git a/Standard Gaming Platform/Font.cpp b/Standard Gaming Platform/Font.cpp index b022d11c..4ecc6d6a 100644 --- a/Standard Gaming Platform/Font.cpp +++ b/Standard Gaming Platform/Font.cpp @@ -403,7 +403,7 @@ UINT32 LoadIndex; void UnloadFont(UINT32 FontIndex) { Assert(FontIndex >= 0); - Assert(FontIndex <= MAX_FONTS); + Assert(FontIndex < MAX_FONTS); Assert(FontObjs[FontIndex]!=NULL); DeleteVideoObject(FontObjs[FontIndex]); diff --git a/Standard Gaming Platform/MemMan.cpp b/Standard Gaming Platform/MemMan.cpp index 97e9bc51..c9f79d90 100644 --- a/Standard Gaming Platform/MemMan.cpp +++ b/Standard Gaming Platform/MemMan.cpp @@ -405,7 +405,7 @@ void MemFreeLocked( PTR ptr, UINT32 uiSize ) if (ptr != NULL) { VirtualUnlock( ptr, uiSize ); - VirtualFree( ptr, uiSize, MEM_RELEASE ); + VirtualFree( ptr, 0, MEM_RELEASE ); guiMemTotal -= uiSize; guiMemFreed += uiSize; diff --git a/Standard Gaming Platform/input.cpp b/Standard Gaming Platform/input.cpp index f4d2c41d..012ddf98 100644 --- a/Standard Gaming Platform/input.cpp +++ b/Standard Gaming Platform/input.cpp @@ -473,6 +473,9 @@ void QueueEvent(UINT16 ubInputEvent, UINT32 usParam, UINT32 uiParam) BOOLEAN DequeueSpecificEvent(InputAtom *Event, UINT32 uiMaskFlags ) { EnterCriticalSection(&gcsInputQueueLock); + + BOOLEAN result = FALSE; + __try { // Is there an event to dequeue @@ -483,16 +486,16 @@ BOOLEAN DequeueSpecificEvent(InputAtom *Event, UINT32 uiMaskFlags ) // Check if it has the masks! if ( ( Event->usEvent & uiMaskFlags ) ) { - return( DequeueEvent( Event) ); + result = DequeueEvent( Event); } } - - return( FALSE ); } __finally { LeaveCriticalSection(&gcsInputQueueLock); } + + return result; } BOOLEAN InternalDequeueEvent(InputAtom *Event) @@ -529,15 +532,18 @@ BOOLEAN InternalDequeueEvent(InputAtom *Event) BOOLEAN DequeueEvent(InputAtom *Event) { + BOOLEAN result = FALSE; __try { EnterCriticalSection(&gcsInputQueueLock); - return InternalDequeueEvent(Event); + result = InternalDequeueEvent(Event); } __finally { LeaveCriticalSection(&gcsInputQueueLock); } + + return result; } diff --git a/Standard Gaming Platform/sgp.cpp b/Standard Gaming Platform/sgp.cpp index 2fb5d523..ded1d9fd 100644 --- a/Standard Gaming Platform/sgp.cpp +++ b/Standard Gaming Platform/sgp.cpp @@ -1871,7 +1871,7 @@ static void PopulateSectionFromCommandLine(vfs::PropertyContainer &oProps, vfs:: wchar_t *psep = wcspbrk(arg, L":="); wchar_t *param = (psep ? psep+1 : NULL); if (psep) *psep = 0; - if ( (param == NULL || param[0] == 0) && ( i+1uiFlags & ( CELL_RETREATING | CELL_RETREATED ) ) { //already retreated/retreating. return; diff --git a/Strategic/LuaInitNPCs.cpp b/Strategic/LuaInitNPCs.cpp index c9a84290..4db81f45 100644 --- a/Strategic/LuaInitNPCs.cpp +++ b/Strategic/LuaInitNPCs.cpp @@ -784,9 +784,9 @@ ACTION_ITEM_VALUES ActionItemsValues[500]; void IniLuaGlobal() { -UINT32 i; + UINT32 i; - for (i= 0; i<=1000; i++ ) + for (i= 0; i<1000; i++ ) { gLuaGlobal[i].fGlobalLuaBool = FALSE; gLuaGlobal[i].iGlobalLuaVal = 0; diff --git a/Strategic/Map Screen Interface Map Inventory.cpp b/Strategic/Map Screen Interface Map Inventory.cpp index d02db56e..b677809a 100644 --- a/Strategic/Map Screen Interface Map Inventory.cpp +++ b/Strategic/Map Screen Interface Map Inventory.cpp @@ -4257,8 +4257,8 @@ void SortSectorInventoryAmmo(bool useBoxes) { // Declarations - INT32 crateItem; - bool mergeSuccessful, ammoPresent; + INT32 crateItem; + bool mergeSuccessful = false; OBJECTTYPE newCrate; int loopCount = 0; @@ -4267,7 +4267,7 @@ void SortSectorInventoryAmmo(bool useBoxes) AssertMsg( pSoldier != NULL, "Sector Inventory: Attempting ammo sort without valid selected soldier?" ); //MM: added for ammo boxes - ammoPresent = true; + bool ammoPresent = true; UINT8 magType = AMMO_CRATE; if (useBoxes) magType = AMMO_BOX; diff --git a/Strategic/strategicmap.cpp b/Strategic/strategicmap.cpp index 3c842569..5755642b 100644 --- a/Strategic/strategicmap.cpp +++ b/Strategic/strategicmap.cpp @@ -1236,7 +1236,7 @@ char temp; else { strncpy(pData->curCityInfo.IconSTI,pData->szCharData,MAX_ICON_CHARS); - pData->curCityInfo.IconSTI[MAX_ICON_CHARS] = '\0'; + pData->curCityInfo.IconSTI[MAX_ICON_CHARS-1] = '\0'; } for(int i=0;iszCharData),MAX_ICON_CHARS);i++) @@ -4209,7 +4209,7 @@ void AllMercsWalkedToExitGrid() /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // SANDRO - reset num enemies here if the sector was unloaded - if( gWorldSectorX == 0 && gWorldSectorX == 0 && gbWorldSectorZ == -1 ) + if( gWorldSectorX == 0 && gWorldSectorY == 0 && gbWorldSectorZ == -1 ) { memset( &(gTacticalStatus.bNumFoughtInBattle), 0, MAXTEAMS ); } @@ -4396,7 +4396,7 @@ void AllMercsHaveWalkedOffSector( ) SetDefaultSquadOnSectorEntry( TRUE ); /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // SANDRO - reset num enemies here if the sector was unloaded - if( !fEnemiesInLoadedSector || (gWorldSectorX == 0 && gWorldSectorX == 0 && gbWorldSectorZ == -1 ) ) + if( !fEnemiesInLoadedSector || (gWorldSectorX == 0 && gWorldSectorY == 0 && gbWorldSectorZ == -1 ) ) { memset( &(gTacticalStatus.bNumFoughtInBattle), 0, MAXTEAMS ); } diff --git a/Tactical/Handle UI.cpp b/Tactical/Handle UI.cpp index 3ec075a7..82442809 100644 --- a/Tactical/Handle UI.cpp +++ b/Tactical/Handle UI.cpp @@ -1604,23 +1604,7 @@ UINT32 UIHandleMOnTerrain( UI_EVENT *pUIEvent ) { if ( !UIHandleInteractiveTilesAndItemsOnTerrain( pSoldier, usMapPos, FALSE, TRUE ) ) { - // Are we in combat? - if ( (gTacticalStatus.uiFlags & INCOMBAT ) && ( gTacticalStatus.uiFlags & TURNBASED ) ) - { - // If so, draw path, etc - fSetCursor = HandleUIMovementCursor( pSoldier, uiCursorFlags, usMapPos, 0 ); - } - else - { - // Donot draw path until confirm - fSetCursor = TRUE; - - // If so, draw path, etc - fSetCursor = HandleUIMovementCursor( pSoldier, uiCursorFlags, usMapPos, 0 ); - - //ErasePath( TRUE ); - } - + fSetCursor = HandleUIMovementCursor( pSoldier, uiCursorFlags, usMapPos, 0 ); } else { diff --git a/Tactical/Interface Enhanced.cpp b/Tactical/Interface Enhanced.cpp index 1721f418..d9c6c936 100644 --- a/Tactical/Interface Enhanced.cpp +++ b/Tactical/Interface Enhanced.cpp @@ -6235,7 +6235,7 @@ void DrawWeaponValues( OBJECTTYPE * gpItemDescObject ) } else { - swprintf( pStr, L"--", iToHitValue ); + swprintf( pStr, L"--" ); } FindFontCenterCoordinates( sLeft, sTop, sWidth, sHeight, pStr, BLOCKFONT2, &usX, &usY); mprintf( usX, usY, pStr ); @@ -6298,7 +6298,7 @@ void DrawWeaponValues( OBJECTTYPE * gpItemDescObject ) } else { - swprintf( pStr, L"--", iBestLaserRangeValue ); + swprintf( pStr, L"--" ); } FindFontCenterCoordinates( sLeft, sTop, sWidth, sHeight, pStr, BLOCKFONT2, &usX, &usY); mprintf( usX, usY, pStr ); @@ -10122,7 +10122,7 @@ void DrawAdvancedValues( OBJECTTYPE *gpItemDescObject ) if (iModifier[cnt2]) { SetFontForeground( ITEMDESC_FONTPOSITIVE ); - swprintf( pStr, L"Y", iModifier[cnt2] ); + swprintf( pStr, L"Y", iModifier[cnt2] ); // FIXME: unused param FindFontCenterCoordinates( sLeft, sTop, sWidth, sHeight, pStr, BLOCKFONT2, &usX, &usY); } else diff --git a/Tactical/Interface Items.cpp b/Tactical/Interface Items.cpp index 3fd9a934..c777dbd9 100644 --- a/Tactical/Interface Items.cpp +++ b/Tactical/Interface Items.cpp @@ -4408,7 +4408,7 @@ void MAPINVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pOb if ( (gTacticalStatus.uiFlags & TURNBASED) && (gTacticalStatus.uiFlags & INCOMBAT) ) { // Soldier doesn't know. - swprintf( pStr, L"%s", "??" ); + swprintf( pStr, L"%s", L"??" ); } else { @@ -4490,7 +4490,7 @@ void MAPINVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pOb if ( (gTacticalStatus.uiFlags & TURNBASED) && (gTacticalStatus.uiFlags & INCOMBAT) ) { // Soldier doesn't know. - swprintf( pStr, L"%s", "??" ); + swprintf( pStr, L"%s", L"??" ); } else { @@ -6501,7 +6501,7 @@ void RenderItemDescriptionBox( ) sOffsetX = hVObject->p16BPPObject->sOffsetX; sOffsetY = hVObject->p16BPPObject->sOffsetY; } - else if(hVObject->ubBitDepth == 32) + else //if(hVObject->ubBitDepth == 32) { usHeight = hVObject->p16BPPObject->usHeight; usWidth = hVObject->p16BPPObject->usWidth; diff --git a/Tactical/Overhead.cpp b/Tactical/Overhead.cpp index 645e45fe..61268d0a 100644 --- a/Tactical/Overhead.cpp +++ b/Tactical/Overhead.cpp @@ -7930,7 +7930,7 @@ void HandleSuppressionFire( UINT8 ubTargetedMerc, UINT8 ubCausedAttacker ) UINT32 uiLoop; UINT8 ubLoop2; // Flag to determine if the target is cowering (if allowed) - BOOLEAN fCower; + BOOLEAN fCower=FALSE; SOLDIERTYPE * pSoldier; // External options diff --git a/Tactical/Soldier Create.cpp b/Tactical/Soldier Create.cpp index 7456d717..3f6a4dbc 100644 --- a/Tactical/Soldier Create.cpp +++ b/Tactical/Soldier Create.cpp @@ -1019,7 +1019,7 @@ SOLDIERTYPE* TacticalCreateSoldier( SOLDIERCREATE_STRUCT *pCreateStruct, UINT8 * case ELDORADO: case ICECREAMTRUCK: case JEEP: - if ( Soldier.ubProfile != HELICOPTER || Soldier.ubProfile != 0 || Soldier.ubProfile != NO_PROFILE || Soldier.ubProfile != TANK_CAR ) + if ( Soldier.ubProfile != HELICOPTER && Soldier.ubProfile != 0 && Soldier.ubProfile != NO_PROFILE && Soldier.ubProfile != TANK_CAR ) { ubVehicleID = Soldier.ubProfile; Soldier.aiData.bNeutral = gNewVehicle[Soldier.ubProfile].bNewNeutral; @@ -3251,7 +3251,7 @@ INT32 GetSittableGridNoInRoom(UINT16 usRoom, BOOLEAN fEnoughSpace) UINT8 ubSectorId = SECTOR(gWorldSectorX, gWorldSectorY); if ( ubSectorId >= 0 && ubSectorId < 256 ) { - for ( UINT32 uiLoop = 0; uiLoop < WORLD_MAX; ++uiLoop ) + for ( INT32 uiLoop = 0; uiLoop < WORLD_MAX; ++uiLoop ) { if ( (gusWorldRoomInfo[ uiLoop ] == usRoom) ) { @@ -3494,9 +3494,11 @@ extern void DistributeInitialGear(MERCPROFILESTRUCT *pProfile); void CopyProfileItems( SOLDIERTYPE *pSoldier, SOLDIERCREATE_STRUCT *pCreateStruct ) { - UINT32 cnt, cnt2; - MERCPROFILESTRUCT * pProfile; - BOOLEAN success, fRet; + UINT32 cnt, cnt2; + MERCPROFILESTRUCT* pProfile; + BOOLEAN success; + BOOLEAN fRet; + pProfile = &(gMercProfiles[pCreateStruct->ubProfile]); @@ -3582,10 +3584,14 @@ void CopyProfileItems( SOLDIERTYPE *pSoldier, SOLDIERCREATE_STRUCT *pCreateStruc } else { + fRet=FALSE; + for ( cnt = 0; cnt < NUM_INV_SLOTS; cnt++ ) { + if ( pProfile->inv[ cnt ] != NOTHING ) { + if ( Item[ pProfile->inv[ cnt ] ].usItemClass == IC_KEY ) { // since keys depend on 2 values, they pretty much have to be hardcoded. diff --git a/Tactical/XML_Drugs.cpp b/Tactical/XML_Drugs.cpp index e53f9f6c..1ff82f5d 100644 --- a/Tactical/XML_Drugs.cpp +++ b/Tactical/XML_Drugs.cpp @@ -230,7 +230,7 @@ BOOLEAN WriteDrugsStats() UINT32 cnt; FilePrintf(hFile,"\r\n"); - for(cnt = 0;cnt < MAXITEMS;cnt++) + for(cnt = 0;cnt < DRUG_TYPE_MAX;cnt++) { FilePrintf(hFile,"\t\r\n"); diff --git a/Tactical/XML_Food.cpp b/Tactical/XML_Food.cpp index 2750ade1..8c5f92bb 100644 --- a/Tactical/XML_Food.cpp +++ b/Tactical/XML_Food.cpp @@ -224,7 +224,7 @@ BOOLEAN WriteFoodStats() UINT32 cnt; FilePrintf(hFile,"\r\n"); - for(cnt = 0; cnt < MAXITEMS; ++cnt) + for(cnt = 0; cnt < FOOD_TYPE_MAX; ++cnt) { FilePrintf(hFile,"\t\r\n"); diff --git a/Tactical/XML_NewFaceGear.cpp b/Tactical/XML_NewFaceGear.cpp index f7884bce..467c8149 100644 --- a/Tactical/XML_NewFaceGear.cpp +++ b/Tactical/XML_NewFaceGear.cpp @@ -123,7 +123,7 @@ faceGearEndElementHandle(void *userData, const XML_Char *name) else { strncpy(pData->curFaceGear.szFile,pData->szCharData,MAX_FACE_GERA_CHARS); - pData->curFaceGear.szFile[MAX_FACE_GERA_CHARS] = '\0'; + pData->curFaceGear.szFile[MAX_FACE_GERA_CHARS-1] = '\0'; } for(int i=0;iszCharData),MAX_FACE_GERA_CHARS);i++) diff --git a/Tactical/XML_SectorLoadscreens.cpp b/Tactical/XML_SectorLoadscreens.cpp index 85f6067b..92471b1a 100644 --- a/Tactical/XML_SectorLoadscreens.cpp +++ b/Tactical/XML_SectorLoadscreens.cpp @@ -118,7 +118,7 @@ sectorLoadscreensEndElementHandle(void *userData, const XML_Char *name) else { strncpy(pData->curSectorLoadscreens.szLocation,pData->szCharData,MAX_LOCATION_CHARS); - pData->curSectorLoadscreens.szLocation[MAX_LOCATION_CHARS] = '\0'; + pData->curSectorLoadscreens.szLocation[MAX_LOCATION_CHARS-1] = '\0'; } for(int i=0;iszCharData),MAX_LOCATION_CHARS);i++) @@ -142,7 +142,7 @@ sectorLoadscreensEndElementHandle(void *userData, const XML_Char *name) else { strncpy(pData->curSectorLoadscreens.szImageFormat,pData->szCharData,MAX_IMAGE_FORMAT_CHARS); - pData->curSectorLoadscreens.szImageFormat[MAX_IMAGE_FORMAT_CHARS] = '\0'; + pData->curSectorLoadscreens.szImageFormat[MAX_IMAGE_FORMAT_CHARS-1] = '\0'; } for(int i=0;iszCharData),MAX_IMAGE_FORMAT_CHARS);i++) @@ -161,7 +161,7 @@ sectorLoadscreensEndElementHandle(void *userData, const XML_Char *name) else { strncpy(pData->curSectorLoadscreens.szDay,pData->szCharData,MAX_IMAGE_PATH_CHARS); - pData->curSectorLoadscreens.szDay[MAX_IMAGE_PATH_CHARS] = '\0'; + pData->curSectorLoadscreens.szDay[MAX_IMAGE_PATH_CHARS-1] = '\0'; } for(int i=0;iszCharData),MAX_IMAGE_PATH_CHARS);i++) @@ -180,7 +180,7 @@ sectorLoadscreensEndElementHandle(void *userData, const XML_Char *name) else { strncpy(pData->curSectorLoadscreens.szNight,pData->szCharData,MAX_IMAGE_PATH_CHARS); - pData->curSectorLoadscreens.szNight[MAX_IMAGE_PATH_CHARS] = '\0'; + pData->curSectorLoadscreens.szNight[MAX_IMAGE_PATH_CHARS-1] = '\0'; } for(int i=0;iszCharData),MAX_IMAGE_PATH_CHARS);i++) @@ -199,7 +199,7 @@ sectorLoadscreensEndElementHandle(void *userData, const XML_Char *name) else { strncpy(pData->curSectorLoadscreens.szDayAlt,pData->szCharData,MAX_IMAGE_PATH_CHARS); - pData->curSectorLoadscreens.szDayAlt[MAX_IMAGE_PATH_CHARS] = '\0'; + pData->curSectorLoadscreens.szDayAlt[MAX_IMAGE_PATH_CHARS-1] = '\0'; } for(int i=0;iszCharData),MAX_IMAGE_PATH_CHARS);i++) @@ -218,7 +218,7 @@ sectorLoadscreensEndElementHandle(void *userData, const XML_Char *name) else { strncpy(pData->curSectorLoadscreens.szNightAlt,pData->szCharData,MAX_IMAGE_PATH_CHARS); - pData->curSectorLoadscreens.szNightAlt[MAX_IMAGE_PATH_CHARS] = '\0'; + pData->curSectorLoadscreens.szNightAlt[MAX_IMAGE_PATH_CHARS-1] = '\0'; } for(int i=0;iszCharData),MAX_IMAGE_PATH_CHARS);i++) diff --git a/Tactical/XML_Vehicles.cpp b/Tactical/XML_Vehicles.cpp index dcda0a01..66c112b3 100644 --- a/Tactical/XML_Vehicles.cpp +++ b/Tactical/XML_Vehicles.cpp @@ -296,10 +296,10 @@ void InitNewVehicles () gNewVehicle[ iCount ].bNewVehicle = FALSE; gNewVehicle[ iCount ].NewPilot = -1; gNewVehicle[ iCount ].NewCarPortraits = -1; - gNewVehicle[ iCount ].szIconFace[MAX_MAIN_VEHICLE_CHARS] = '\0'; - gNewVehicle[ iCount ].NewVehicleStrings[128] = '\0'; - gNewVehicle[ iCount ].NewVehicleName[128] = '\0'; - gNewVehicle[ iCount ].NewShortVehicleStrings[128] = '\0'; + gNewVehicle[ iCount ].szIconFace[MAX_MAIN_VEHICLE_CHARS-1] = '\0'; + gNewVehicle[ iCount ].NewVehicleStrings[127] = '\0'; + gNewVehicle[ iCount ].NewVehicleName[127] = '\0'; + gNewVehicle[ iCount ].NewShortVehicleStrings[127] = '\0'; gNewVehicle[ iCount ].NewUsed = FALSE; } } diff --git a/TacticalAI/NPC.cpp b/TacticalAI/NPC.cpp index 36ac2c0c..57472998 100644 --- a/TacticalAI/NPC.cpp +++ b/TacticalAI/NPC.cpp @@ -2328,41 +2328,46 @@ void Converse( UINT8 ubNPC, UINT8 ubMerc, INT8 bApproach, UINT32 uiApproachData { pSoldier = FindSoldierByProfileID( ubNPC, FALSE ); - // stupid hack CC - if (pSoldier && ubNPC == KYLE) - { - // make sure he has keys - pSoldier->flags.bHasKeys = TRUE; - } - if (pSoldier && pSoldier->sGridNo == pQuotePtr->usGoToGridNo ) - { - // search for quotes to trigger immediately! - pSoldier->ubQuoteRecord = ubRecordNum + 1; // add 1 so that the value is guaranteed nonzero - NPCReachedDestination( pSoldier, TRUE ); - } - else - { - // turn off cowering - if ( pNPC->flags.uiStatusFlags & SOLDIER_COWERING) - { - //pNPC->flags.uiStatusFlags &= ~SOLDIER_COWERING; - pNPC->EVENT_InitNewSoldierAnim( STANDING, 0 , FALSE ); - } + + if (pSoldier) + { + // stupid hack CC + if (ubNPC == KYLE) + { + // make sure he has keys + pSoldier->flags.bHasKeys = TRUE; + } - pSoldier->ubQuoteRecord = ubRecordNum + 1; // add 1 so that the value is guaranteed nonzero + if (pSoldier->sGridNo == pQuotePtr->usGoToGridNo ) + { + // search for quotes to trigger immediately! + pSoldier->ubQuoteRecord = ubRecordNum + 1; // add 1 so that the value is guaranteed nonzero + NPCReachedDestination( pSoldier, TRUE ); + } + else + { + // turn off cowering + if ( pNPC->flags.uiStatusFlags & SOLDIER_COWERING) // FIXME: Dereferencing null pointer + { + //pNPC->flags.uiStatusFlags &= ~SOLDIER_COWERING; + pNPC->EVENT_InitNewSoldierAnim( STANDING, 0 , FALSE ); + } - if (pQuotePtr->sActionData == NPC_ACTION_TELEPORT_NPC) - { - BumpAnyExistingMerc( pQuotePtr->usGoToGridNo ); - TeleportSoldier( pSoldier, pQuotePtr->usGoToGridNo, FALSE ); - // search for quotes to trigger immediately! - NPCReachedDestination( pSoldier, FALSE ); - } - else - { - NPCGotoGridNo( ubNPC, pQuotePtr->usGoToGridNo, ubRecordNum ); - } - } + pSoldier->ubQuoteRecord = ubRecordNum + 1; // add 1 so that the value is guaranteed nonzero + + if (pQuotePtr->sActionData == NPC_ACTION_TELEPORT_NPC) + { + BumpAnyExistingMerc( pQuotePtr->usGoToGridNo ); + TeleportSoldier( pSoldier, pQuotePtr->usGoToGridNo, FALSE ); + // search for quotes to trigger immediately! + NPCReachedDestination( pSoldier, FALSE ); + } + else + { + NPCGotoGridNo( ubNPC, pQuotePtr->usGoToGridNo, ubRecordNum ); + } + } + } } // Trigger other NPC? diff --git a/TileEngine/Explosion Control.cpp b/TileEngine/Explosion Control.cpp index c001a984..8a465dff 100644 --- a/TileEngine/Explosion Control.cpp +++ b/TileEngine/Explosion Control.cpp @@ -650,7 +650,7 @@ BOOLEAN ExplosiveDamageStructureAtGridNo( STRUCTURE * pCurrent, STRUCTURE **ppNe #ifdef JA2BETAVERSION if (is_networked) { CHAR tmpMPDbgString[512]; - sprintf(tmpMPDbgString,"ExplosiveDamageStructureAtGridNo ( sGridNo : %i , sWoundAmt : %i , uiDist : %i , fRecompMoveCosts : %i , fOnlyWalls : %i , SubsMulTilTransDmg : %i , ubOwner : %i , bLevel : %i )\n",sGridNo, sWoundAmt , (int)*pfRecompileMovementCosts , (int)fOnlyWalls , (int)fSubSequentMultiTilesTransitionDamage , ubOwner , bLevel ); + sprintf(tmpMPDbgString,"ExplosiveDamageStructureAtGridNo ( sGridNo : %i , sWoundAmt : %i , uiDist : %i , fRecompMoveCosts : %i , fOnlyWalls : %i , SubsMulTilTransDmg : %i , ubOwner : %i , bLevel : %i )\n", sGridNo, sWoundAmt , uiDist, (int)*pfRecompileMovementCosts , (int)fOnlyWalls , (int)fSubSequentMultiTilesTransitionDamage , ubOwner , bLevel ); MPDebugMsg(tmpMPDbgString); } #endif @@ -1324,7 +1324,7 @@ void ExplosiveDamageGridNo( INT32 sGridNo, INT16 sWoundAmt, UINT32 uiDist, BOOLE #ifdef JA2BETAVERSION if (is_networked) { CHAR tmpMPDbgString[512]; - sprintf(tmpMPDbgString,"ExplosiveDamageGridNo ( sGridNo : %i , sWoundAmt : %i , uiDist : %i , fRecompileMoveCosts : %i , fOnlyWalls : %i , MultiStructSpecialFlag : %i ,fSubsequentMultiTilesTransDmg : %i , ubOwner : %i , bLevel : %i )\n",sGridNo, sWoundAmt , (int)*pfRecompileMovementCosts , (int)fOnlyWalls , bMultiStructSpecialFlag , (int)fSubSequentMultiTilesTransitionDamage , ubOwner , bLevel ); + sprintf(tmpMPDbgString,"ExplosiveDamageGridNo ( sGridNo : %i , sWoundAmt : %i , uiDist : %i , fRecompileMoveCosts : %i , fOnlyWalls : %i , MultiStructSpecialFlag : %i ,fSubsequentMultiTilesTransDmg : %i , ubOwner : %i , bLevel : %i )\n", sGridNo, sWoundAmt ,uiDist, (int)*pfRecompileMovementCosts , (int)fOnlyWalls , bMultiStructSpecialFlag , (int)fSubSequentMultiTilesTransitionDamage , ubOwner , bLevel ); MPDebugMsg(tmpMPDbgString); } #endif diff --git a/TileEngine/physics.cpp b/TileEngine/physics.cpp index 358b4306..0d8a9aff 100644 --- a/TileEngine/physics.cpp +++ b/TileEngine/physics.cpp @@ -2399,6 +2399,8 @@ BOOLEAN CheckForCatcher( REAL_OBJECT *pObject, UINT16 usStructureID ) void CheckForObjectHittingMerc( REAL_OBJECT *pObject, UINT16 usStructureID ) { + Assert(usStructureIDcurMainMenu.FileName,pData->szCharData,MAX_MAIN_MENU_CHARS); - pData->curMainMenu.FileName[MAX_MAIN_MENU_CHARS] = '\0'; + pData->curMainMenu.FileName[MAX_MAIN_MENU_CHARS-1] = '\0'; } - for(int i=0;iszCharData),MAX_MAIN_MENU_CHARS);i++) - { + for(int i=0;iszCharData),MAX_MAIN_MENU_CHARS);i++) { temp = pData->szCharData[i]; pData->curMainMenu.FileName[i] = temp; //DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("itemEndElementHandle: szLocation[%d] = %s, temp = %s",i,&pData->curSectorLoadscreens.szLocation[i],&temp));