comparison Items.cpp @ 2369:bddcaf5d5db2

removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
author Grumpy7
date Mon, 12 May 2014 01:50:32 +0200
parents a574a80e7012
children 48dbf99c0f7f
comparison
equal deleted inserted replaced
2368:91b6c0a338ad 2369:bddcaf5d5db2
281 } 281 }
282 282
283 //----- (0045814E) -------------------------------------------------------- 283 //----- (0045814E) --------------------------------------------------------
284 void ItemsTable::Release() 284 void ItemsTable::Release()
285 { 285 {
286 if ( pMonstersTXT_Raw ) 286 free(pMonstersTXT_Raw);
287 free(pMonstersTXT_Raw); 287 free(pMonsterPlacementTXT_Raw);
288 if ( pMonsterPlacementTXT_Raw ) 288 free(pSkillDescTXT_Raw);
289 free(pMonsterPlacementTXT_Raw); 289 free(pSpcItemsTXT_Raw);
290 if ( pSkillDescTXT_Raw ) 290 free(pStdItemsTXT_Raw);
291 free(pSkillDescTXT_Raw); 291 free(pRndItemsTXT_Raw);
292 if (pSpcItemsTXT_Raw ) 292 free(pItemsTXT_Raw);
293 free(pSpcItemsTXT_Raw); 293 free(pHostileTXT_Raw);
294 if ( pStdItemsTXT_Raw ) 294 free(pHistoryTXT_Raw);
295 free(pStdItemsTXT_Raw); 295 free(pPotionsTXT_Raw);
296 if ( pRndItemsTXT_Raw ) 296 free(pPotionNotesTXT_Raw);
297 free(pRndItemsTXT_Raw); 297 pMonstersTXT_Raw = nullptr;
298 if ( pItemsTXT_Raw ) 298 pMonsterPlacementTXT_Raw = nullptr;
299 free(pItemsTXT_Raw); 299 pSpcItemsTXT_Raw = nullptr;
300 if ( pHostileTXT_Raw ) 300 pSkillDescTXT_Raw = nullptr;
301 free(pHostileTXT_Raw); 301 pStdItemsTXT_Raw = nullptr;
302 if ( pHistoryTXT_Raw ) 302 pRndItemsTXT_Raw = nullptr;
303 free(pHistoryTXT_Raw); 303 pItemsTXT_Raw = nullptr;
304 if ( pPotionsTXT_Raw ) 304 pHostileTXT_Raw = nullptr;
305 free(pPotionsTXT_Raw); 305 pHistoryTXT_Raw = nullptr;
306 if ( pPotionNotesTXT_Raw ) 306 pPotionsTXT_Raw = nullptr;
307 free(pPotionNotesTXT_Raw); 307 pPotionNotesTXT_Raw = nullptr;
308 pSpcItemsTXT_Raw = NULL;
309 pSkillDescTXT_Raw = NULL;
310 pStdItemsTXT_Raw = NULL;
311 pRndItemsTXT_Raw = NULL;
312 pItemsTXT_Raw = NULL;
313 } 308 }
314 309
315 310
316 //----- (00456D84) -------------------------------------------------------- 311 //----- (00456D84) --------------------------------------------------------
317 void ItemsTable::Initialize() 312 void ItemsTable::Initialize()
381 pFactionTable->Initialize(); 376 pFactionTable->Initialize();
382 377
383 pStorylineText = new StorylineText; 378 pStorylineText = new StorylineText;
384 pStorylineText->Initialize(); 379 pStorylineText->Initialize();
385 380
386 pStdItemsTXT_Raw = NULL;
387 pStdItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("stditems.txt", 0); 381 pStdItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("stditems.txt", 0);
388 strtok(pStdItemsTXT_Raw, "\r"); 382 strtok(pStdItemsTXT_Raw, "\r");
389 strtok(NULL, "\r"); 383 strtok(NULL, "\r");
390 strtok(NULL, "\r"); 384 strtok(NULL, "\r");
391 strtok(NULL, "\r"); 385 strtok(NULL, "\r");
423 bonus_ranges[i].minR = atoi(tokens[2]); 417 bonus_ranges[i].minR = atoi(tokens[2]);
424 bonus_ranges[i].maxR =atoi(tokens[3]); 418 bonus_ranges[i].maxR =atoi(tokens[3]);
425 } 419 }
426 420
427 421
428 pSpcItemsTXT_Raw = 0;
429 pSpcItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("spcitems.txt", 0); 422 pSpcItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("spcitems.txt", 0);
430 strtok(pSpcItemsTXT_Raw, "\r"); 423 strtok(pSpcItemsTXT_Raw, "\r");
431 strtok(NULL, "\r"); 424 strtok(NULL, "\r");
432 strtok(NULL, "\r"); 425 strtok(NULL, "\r");
433 strtok(NULL, "\r"); 426 strtok(NULL, "\r");
463 pSpecialEnchantmentsSumm[i]+=pSpecialEnchantments[j].to_item_apply[i]; 456 pSpecialEnchantmentsSumm[i]+=pSpecialEnchantments[j].to_item_apply[i];
464 } 457 }
465 458
466 InitializeBuildingResidents(); 459 InitializeBuildingResidents();
467 460
468 pItemsTXT_Raw = NULL;
469 pItemsTXT_Raw = (char*) pEvents_LOD->LoadRaw("items.txt", 0); 461 pItemsTXT_Raw = (char*) pEvents_LOD->LoadRaw("items.txt", 0);
470 strtok(pItemsTXT_Raw, "\r"); 462 strtok(pItemsTXT_Raw, "\r");
471 strtok(NULL, "\r"); 463 strtok(NULL, "\r");
472 uAllItemsCount = 0; 464 uAllItemsCount = 0;
473 item_counter = 0; 465 item_counter = 0;
545 pItems[item_counter].uEquipY=atoi(tokens[15]); 537 pItems[item_counter].uEquipY=atoi(tokens[15]);
546 pItems[item_counter].pDescription = RemoveQuotes(tokens[16]); 538 pItems[item_counter].pDescription = RemoveQuotes(tokens[16]);
547 item_counter++; 539 item_counter++;
548 } 540 }
549 541
550 pRndItemsTXT_Raw = NULL;
551 uAllItemsCount = item_counter; 542 uAllItemsCount = item_counter;
552 pRndItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("rnditems.txt", 0); 543 pRndItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("rnditems.txt", 0);
553 strtok(pRndItemsTXT_Raw, "\r"); 544 strtok(pRndItemsTXT_Raw, "\r");
554 strtok(NULL, "\r"); 545 strtok(NULL, "\r");
555 strtok(NULL, "\r"); 546 strtok(NULL, "\r");
612 uBonusChanceWpSpecial[4]=atoi(tokens[6]); 603 uBonusChanceWpSpecial[4]=atoi(tokens[6]);
613 uBonusChanceWpSpecial[5]=atoi(tokens[7]); 604 uBonusChanceWpSpecial[5]=atoi(tokens[7]);
614 break; 605 break;
615 } 606 }
616 } 607 }
617 608 free(pRndItemsTXT_Raw);
618 if ( pRndItemsTXT_Raw ) 609 pRndItemsTXT_Raw = nullptr;
619 { 610
620 free(pRndItemsTXT_Raw);
621 pRndItemsTXT_Raw = NULL;
622 }
623
624 pSkillDescTXT_Raw = NULL;
625 pSkillDescTXT_Raw = (char *)pEvents_LOD->LoadRaw("skilldes.txt", 0); 611 pSkillDescTXT_Raw = (char *)pEvents_LOD->LoadRaw("skilldes.txt", 0);
626 strtok(pSkillDescTXT_Raw, "\r"); 612 strtok(pSkillDescTXT_Raw, "\r");
627 for (int i=0; i<37; ++i) 613 for (int i=0; i<37; ++i)
628 { 614 {
629 test_string = strtok(NULL, "\r") + 1; 615 test_string = strtok(NULL, "\r") + 1;
634 pExpertSkillDesc[i] = RemoveQuotes(tokens[3]); 620 pExpertSkillDesc[i] = RemoveQuotes(tokens[3]);
635 pMasterSkillDesc[i] = RemoveQuotes(tokens[4]); 621 pMasterSkillDesc[i] = RemoveQuotes(tokens[4]);
636 pGrandSkillDesc[i] = RemoveQuotes(tokens[5]); 622 pGrandSkillDesc[i] = RemoveQuotes(tokens[5]);
637 } 623 }
638 624
639 pStatsTXT_Raw = 0;
640 pStatsTXT_Raw = (char *)pEvents_LOD->LoadRaw("stats.txt", 0); 625 pStatsTXT_Raw = (char *)pEvents_LOD->LoadRaw("stats.txt", 0);
641 strtok(pStatsTXT_Raw, "\r"); 626 strtok(pStatsTXT_Raw, "\r");
642 for (int i=0; i<26; ++i) 627 for (int i=0; i<26; ++i)
643 { 628 {
644 test_string = strtok(NULL, "\r") + 1; 629 test_string = strtok(NULL, "\r") + 1;
769 char* test_string; 754 char* test_string;
770 unsigned int uRow; 755 unsigned int uRow;
771 unsigned int uColumn; 756 unsigned int uColumn;
772 unsigned __int8 potion_value; 757 unsigned __int8 potion_value;
773 758
774 if ( pPotionNotesTXT_Raw ) 759 free(pPotionNotesTXT_Raw);
775 free(pPotionNotesTXT_Raw);
776 pPotionNotesTXT_Raw = NULL;
777 auto tokens = Tokenize("", '\t'); 760 auto tokens = Tokenize("", '\t');
778 char* pPotionsTXT_Raw = (char *)pEvents_LOD->LoadRaw("potion.txt", 0); 761 char* pPotionsTXT_Raw = (char *)pEvents_LOD->LoadRaw("potion.txt", 0);
779 test_string = strtok(pPotionsTXT_Raw ,"\r") + 1; 762 test_string = strtok(pPotionsTXT_Raw ,"\r") + 1;
780 while (test_string) 763 while (test_string)
781 { 764 {
828 char* test_string; 811 char* test_string;
829 unsigned int uRow; 812 unsigned int uRow;
830 unsigned int uColumn; 813 unsigned int uColumn;
831 unsigned __int8 potion_note; 814 unsigned __int8 potion_note;
832 815
833 if ( pPotionNotesTXT_Raw ) 816 free(pPotionNotesTXT_Raw);
834 free(pPotionNotesTXT_Raw);
835 pPotionNotesTXT_Raw = NULL;
836 auto tokens = Tokenize("", '\t'); 817 auto tokens = Tokenize("", '\t');
837 char* pPotionNotesTXT_Raw = (char *)pEvents_LOD->LoadRaw("potnotes.txt", 0); 818 char* pPotionNotesTXT_Raw = (char *)pEvents_LOD->LoadRaw("potnotes.txt", 0);
838 test_string = strtok(pPotionNotesTXT_Raw ,"\r") + 1; 819 test_string = strtok(pPotionNotesTXT_Raw ,"\r") + 1;
839 while (test_string) 820 while (test_string)
840 { 821 {