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
This commit is contained in:
Flugente
2013-05-27 20:38:52 +00:00
parent 921394b24c
commit f92f70c78d
39 changed files with 167 additions and 149 deletions
+4
View File
@@ -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;
+4 -4
View File
@@ -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<giNumberOfNewBobbyRShipment; iCnt++ )
+2 -2
View File
@@ -164,7 +164,7 @@ void HandleCharProfile()
if( fDoneLoadPending == FALSE )
{
//make sure we are not hosing memory
Assert( iCurrentImpPage <= IMP_NUM_PAGES );
Assert( iCurrentImpPage < IMP_NUM_PAGES );
fFastLoadFlag = HasTheCurrentIMPPageBeenVisited( );
@@ -808,7 +808,7 @@ BOOLEAN HasTheCurrentIMPPageBeenVisited( void )
// returns if we have vsisted the current IMP PageAlready
//make sure we are not hosing memory
Assert( iCurrentImpPage <= IMP_NUM_PAGES );
Assert( iCurrentImpPage < IMP_NUM_PAGES );
return ( fVisitedIMPSubPages[ iCurrentImpPage ]);
}
+1 -1
View File
@@ -1232,7 +1232,7 @@ INT32 iBonusPointsNeededForLevelUp()
INT32 iBonusPointsRecievedForLevelDown()
{
INT32 iBonusPointsRecieved;
INT32 iBonusPointsRecieved=0;
if (iStartingLevel > 1 && iStartingLevel <= 10)
{
+1
View File
@@ -1691,6 +1691,7 @@ void GiveIMPRandomItems( MERCPROFILESTRUCT *pProfile, UINT8 typeIndex )
MakeProfileInvItemAnySlot(pProfile,usItem,100,1);
// give ammo for guns
Assert(usItem<MAXITEMS);
if ( Item[usItem].usItemClass == IC_GUN && !Item[usItem].rocketlauncher )
{
usItem = DefaultMagazine(usItem);
+1 -1
View File
@@ -304,7 +304,7 @@ void HandleIMPDisabilityTraitAnswers( UINT32 uiSkillPressed )
}
//make sure its a valid disability trait
if( uiSkillPressed > IMP_DISABILITIES_NUMBER )
if( uiSkillPressed >= IMP_DISABILITIES_NUMBER )
{
Assert( 0 );
return;
+1 -1
View File
@@ -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;
+16 -15
View File
@@ -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]);
+8 -8
View File
@@ -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;i<min((int)strlen(pData->szCharData),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;i<min((int)strlen(pData->szCharData),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;i<min((int)strlen(pData->szCharData),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;i<min((int)strlen(pData->szCharData),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;i<min((int)strlen(pData->szCharData),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;i<min((int)strlen(pData->szCharData),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;i<min((int)strlen(pData->szCharData),MAX_ENCYCLOPEDIA_CHARS);i++)
+1 -1
View File
@@ -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
+2
View File
@@ -746,6 +746,8 @@ void DrawRecordsColumnHeadersText( void )
void DrawRecordsText( void )
{
Assert(pFinanceListHead);
// draws the text of the records
FinanceUnitPtr pCurFinance=pCurrentFinance;
FinanceUnitPtr pTempFinance=pFinanceListHead;
+3 -4
View File
@@ -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 )
{