diff options
author | Nay <dnpd.dd@gmail.com> | 2013-08-24 22:56:29 +0100 |
---|---|---|
committer | Nay <dnpd.dd@gmail.com> | 2013-08-24 22:57:22 +0100 |
commit | 12973de799dde8f89b9049964e26ab63a960520a (patch) | |
tree | 2f1d0c6346c71f1c9543aa9fb497af3d12053249 | |
parent | 61016dcc66eaeef26dd21d3f5cf7323809a76080 (diff) |
Core&Tools: Fix multiple issues found by a static code coverage tool
23 files changed, 93 insertions, 47 deletions
diff --git a/src/server/collision/Maps/TileAssembler.cpp b/src/server/collision/Maps/TileAssembler.cpp index 4b61e5da40b..c0797b0fdcc 100644 --- a/src/server/collision/Maps/TileAssembler.cpp +++ b/src/server/collision/Maps/TileAssembler.cpp @@ -98,7 +98,16 @@ namespace VMAP printf("Creating map tree for map %u...\n", map_iter->first); BIH pTree; - pTree.build(mapSpawns, BoundsTrait<ModelSpawn*>::getBounds); + + try + { + pTree.build(mapSpawns, BoundsTrait<ModelSpawn*>::getBounds); + } + catch (std::exception& e) + { + printf("Exception ""%s"" when calling pTree.build", e.what()); + return false; + } // ===> possibly move this code to StaticMapTree class std::map<uint32, uint32> modelNodeIdx; diff --git a/src/server/game/Chat/Chat.cpp b/src/server/game/Chat/Chat.cpp index 0b18a04c5ca..f61380b6834 100644 --- a/src/server/game/Chat/Chat.cpp +++ b/src/server/game/Chat/Chat.cpp @@ -696,13 +696,12 @@ void ChatHandler::FillMessageData(WorldPacket* data, WorldSession* session, uint *data << uint32(0); // 2.1.0 *data << uint32(speaker->GetName().size() + 1); *data << speaker->GetName(); - uint64 listener_guid = 0; - *data << uint64(listener_guid); - if (listener_guid && !IS_PLAYER_GUID(listener_guid)) - { - *data << uint32(1); // string listener_name_length - *data << uint8(0); // string listener_name - } + *data << uint64(0); // listener_guid + //if (listener_guid && !IS_PLAYER_GUID(listener_guid)) + //{ + // *data << uint32(1); // string listener_name_length + // *data << uint8(0); // string listener_name + //} *data << uint32(messageLength); *data << message; *data << uint8(0); diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 2ff86f81880..8f3379ee254 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -6878,10 +6878,8 @@ void Player::CheckAreaExploreAndOutdoor() } else if (diff > 5) { - int32 exploration_percent = (100-((diff-5)*5)); - if (exploration_percent > 100) - exploration_percent = 100; - else if (exploration_percent < 0) + int32 exploration_percent = 100 - ((diff - 5) * 5); + if (exploration_percent < 0) exploration_percent = 0; XP = uint32(sObjectMgr->GetBaseXP(areaEntry->area_level)*exploration_percent/100*sWorld->getRate(RATE_XP_EXPLORE)); diff --git a/src/server/game/Spells/Auras/SpellAuras.cpp b/src/server/game/Spells/Auras/SpellAuras.cpp index 149f422554a..d7b8003f19a 100644 --- a/src/server/game/Spells/Auras/SpellAuras.cpp +++ b/src/server/game/Spells/Auras/SpellAuras.cpp @@ -2411,6 +2411,7 @@ void UnitAura::FillTargetMap(std::map<Unit*, uint8> & targets, Unit* caster) } case SPELL_EFFECT_APPLY_AREA_AURA_PET: targetList.push_back(GetUnitOwner()); + // no break case SPELL_EFFECT_APPLY_AREA_AURA_OWNER: { if (Unit* owner = GetUnitOwner()->GetCharmerOrOwner()) diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 539b38bdac4..b502717178e 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -6129,6 +6129,7 @@ SpellCastResult Spell::CheckItems() return SPELL_FAILED_DONT_REPORT; } } + // no break case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC: { Item* targetItem = m_targets.GetItemTarget(); diff --git a/src/server/game/Spells/SpellMgr.cpp b/src/server/game/Spells/SpellMgr.cpp index ebf7121eb54..e42d0f40998 100644 --- a/src/server/game/Spells/SpellMgr.cpp +++ b/src/server/game/Spells/SpellMgr.cpp @@ -1236,7 +1236,7 @@ void SpellMgr::LoadSpellTalentRanks() node.rank = rank + 1; node.prev = prevSpell; - node.next = node.rank < MAX_TALENT_RANK ? GetSpellInfo(talentInfo->RankID[rank + 1]) : NULL; + node.next = node.rank < MAX_TALENT_RANK ? GetSpellInfo(talentInfo->RankID[node.rank]) : NULL; mSpellChains[spellId] = node; mSpellInfoMap[spellId]->ChainEntry = &mSpellChains[spellId]; @@ -2782,6 +2782,9 @@ void SpellMgr::LoadSpellInfoCustomAttributes() { uint32 enchantId = spellInfo->Effects[j].MiscValue; SpellItemEnchantmentEntry const* enchant = sSpellItemEnchantmentStore.LookupEntry(enchantId); + if (!enchant) + break; + for (uint8 s = 0; s < MAX_ITEM_ENCHANTMENT_EFFECTS; ++s) { if (enchant->type[s] != ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL) @@ -3769,10 +3772,10 @@ void SpellMgr::LoadSpellInfoCorrections() } } - SummonPropertiesEntry* properties = const_cast<SummonPropertiesEntry*>(sSummonPropertiesStore.LookupEntry(121)); - properties->Type = SUMMON_TYPE_TOTEM; - properties = const_cast<SummonPropertiesEntry*>(sSummonPropertiesStore.LookupEntry(647)); // 52893 - properties->Type = SUMMON_TYPE_TOTEM; + if (SummonPropertiesEntry* properties = const_cast<SummonPropertiesEntry*>(sSummonPropertiesStore.LookupEntry(121))) + properties->Type = SUMMON_TYPE_TOTEM; + if (SummonPropertiesEntry* properties = const_cast<SummonPropertiesEntry*>(sSummonPropertiesStore.LookupEntry(647))) // 52893 + properties->Type = SUMMON_TYPE_TOTEM; TC_LOG_INFO(LOG_FILTER_SERVER_LOADING, ">> Loaded SpellInfo corrections in %u ms", GetMSTimeDiffToNow(oldMSTime)); } diff --git a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackwingLair/boss_razorgore.cpp b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackwingLair/boss_razorgore.cpp index be2aeb9e223..caf2719eff9 100644 --- a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackwingLair/boss_razorgore.cpp +++ b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackwingLair/boss_razorgore.cpp @@ -169,7 +169,7 @@ public: { if (InstanceScript* instance = go->GetInstanceScript()) if (instance->GetData(DATA_EGG_EVENT) != DONE) - if (Creature* razor = Unit::GetCreature(*go, instance ? instance->GetData64(DATA_RAZORGORE_THE_UNTAMED) : 0)) + if (Creature* razor = Unit::GetCreature(*go, instance->GetData64(DATA_RAZORGORE_THE_UNTAMED))) { razor->Attack(player, true); player->CastSpell(razor, SPELL_MINDCONTROL); diff --git a/src/server/scripts/EasternKingdoms/SunwellPlateau/boss_eredar_twins.cpp b/src/server/scripts/EasternKingdoms/SunwellPlateau/boss_eredar_twins.cpp index 0e58cb85c4b..d402eccedd4 100644 --- a/src/server/scripts/EasternKingdoms/SunwellPlateau/boss_eredar_twins.cpp +++ b/src/server/scripts/EasternKingdoms/SunwellPlateau/boss_eredar_twins.cpp @@ -473,6 +473,7 @@ public: { case SPELL_BLAZE: target->CastSpell(target, SPELL_BLAZE_SUMMON, true); + break; case SPELL_CONFLAGRATION: case SPELL_FLAME_SEAR: HandleTouchedSpells(target, SPELL_FLAME_TOUCHED); diff --git a/src/server/scripts/EasternKingdoms/zone_redridge_mountains.cpp b/src/server/scripts/EasternKingdoms/zone_redridge_mountains.cpp index 20a47325a9c..6609f8a9d46 100644 --- a/src/server/scripts/EasternKingdoms/zone_redridge_mountains.cpp +++ b/src/server/scripts/EasternKingdoms/zone_redridge_mountains.cpp @@ -139,10 +139,12 @@ public: Talk(SAY_CORPORAL_4); uiTimer = 2500; uiPhase = 5; + break; case 5: Talk(SAY_CORPORAL_5); uiTimer = 0; uiPhase = 0; + break; } } else uiTimer -= uiDiff; } diff --git a/src/server/scripts/EasternKingdoms/zone_western_plaguelands.cpp b/src/server/scripts/EasternKingdoms/zone_western_plaguelands.cpp index 4057f4070b1..8937e896faf 100644 --- a/src/server/scripts/EasternKingdoms/zone_western_plaguelands.cpp +++ b/src/server/scripts/EasternKingdoms/zone_western_plaguelands.cpp @@ -361,13 +361,12 @@ public: break; case 15: Talk(SAY_WP_2); + break; case 21: Theldanis = GetClosestCreatureWithEntry(me, NPC_THEL_DANIS, 150); if (Theldanis) Theldanis->AI()->Talk(SAY_WP_3); break; - case 22: - break; case 23: Ughost = me->SummonCreature(NPC_GHOST_UTHER, 971.86f, -1825.42f, 81.99f, 0.0f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 30000); if (Ughost) diff --git a/src/server/scripts/Northrend/VioletHold/instance_violet_hold.cpp b/src/server/scripts/Northrend/VioletHold/instance_violet_hold.cpp index 025e93ac8d9..60d7570b96f 100644 --- a/src/server/scripts/Northrend/VioletHold/instance_violet_hold.cpp +++ b/src/server/scripts/Northrend/VioletHold/instance_violet_hold.cpp @@ -608,6 +608,7 @@ public: if (GameObject* pMainDoor = instance->GetGameObject(uiMainDoor)) pMainDoor->SetGoState(GO_STATE_READY); DoUpdateWorldState(WORLD_STATE_VH_PRISON_STATE, 100); + // no break } default: SpawnPortal(); diff --git a/src/server/scripts/Northrend/zone_borean_tundra.cpp b/src/server/scripts/Northrend/zone_borean_tundra.cpp index da8511a98d5..2b5508272d9 100644 --- a/src/server/scripts/Northrend/zone_borean_tundra.cpp +++ b/src/server/scripts/Northrend/zone_borean_tundra.cpp @@ -90,7 +90,7 @@ public: } } - void EnterCombat(Unit* /*who*/)OVERRIDE {} + void EnterCombat(Unit* /*who*/) OVERRIDE {} void UpdateAI(uint32 diff) OVERRIDE { @@ -119,7 +119,8 @@ public: case 3: DoCast(me, SPELL_EXPLODE_CART, true); phaseTimer = 2000; - phase = 4; + phase = 5; // @fixme: phase 4 is missing... + break; case 5: DoCast(me, SPELL_SUMMON_WORM, true); if (Unit* worm = me->FindNearestCreature(26250, 3)) diff --git a/src/server/scripts/Spells/spell_shaman.cpp b/src/server/scripts/Spells/spell_shaman.cpp index 3a02a8b8c09..eb717315179 100644 --- a/src/server/scripts/Spells/spell_shaman.cpp +++ b/src/server/scripts/Spells/spell_shaman.cpp @@ -521,9 +521,9 @@ class spell_sha_flame_shock : public SpellScriptLoader // Lava Flows if (AuraEffect const* aurEff = caster->GetDummyAuraEffect(SPELLFAMILY_SHAMAN, SHAMAN_ICON_ID_SHAMAN_LAVA_FLOW, EFFECT_0)) { - SpellInfo const* firstRankSpellInfo = sSpellMgr->GetSpellInfo(SPELL_SHAMAN_LAVA_FLOWS_R1); - if (!aurEff->GetSpellInfo()->IsRankOf(firstRankSpellInfo)) - return; + if (SpellInfo const* firstRankSpellInfo = sSpellMgr->GetSpellInfo(SPELL_SHAMAN_LAVA_FLOWS_R1)) + if (!aurEff->GetSpellInfo()->IsRankOf(firstRankSpellInfo)) + return; uint8 rank = aurEff->GetSpellInfo()->GetRank(); caster->CastSpell(caster, sSpellMgr->GetSpellWithRank(SPELL_SHAMAN_LAVA_FLOWS_TRIGGERED_R1, rank), true); diff --git a/src/server/shared/Database/QueryResult.cpp b/src/server/shared/Database/QueryResult.cpp index 4f4c0ec51f4..9413e28a0c0 100644 --- a/src/server/shared/Database/QueryResult.cpp +++ b/src/server/shared/Database/QueryResult.cpp @@ -60,6 +60,9 @@ m_length(NULL) if (mysql_stmt_store_result(m_stmt)) { TC_LOG_WARN(LOG_FILTER_SQL, "%s:mysql_stmt_store_result, cannot bind result from MySQL server. Error: %s", __FUNCTION__, mysql_stmt_error(m_stmt)); + delete[] m_rBind; + delete[] m_isNull; + delete[] m_length; return; } diff --git a/src/server/shared/Utilities/Util.h b/src/server/shared/Utilities/Util.h index a379bfd32fc..a5b2a7b9cc2 100644 --- a/src/server/shared/Utilities/Util.h +++ b/src/server/shared/Utilities/Util.h @@ -173,7 +173,7 @@ inline bool isExtendedLatinCharacter(wchar_t wchar) return true; if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS return true; - if (wchar >= 0x00D8 && wchar <= 0x00DF) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN + if (wchar >= 0x00D8 && wchar <= 0x00DE) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN return true; if (wchar == 0x00DF) // LATIN SMALL LETTER SHARP S return true; diff --git a/src/tools/map_extractor/mpq_libmpq04.h b/src/tools/map_extractor/mpq_libmpq04.h index 9f0163067c4..4691693d80d 100644 --- a/src/tools/map_extractor/mpq_libmpq04.h +++ b/src/tools/map_extractor/mpq_libmpq04.h @@ -18,6 +18,7 @@ public: mpq_archive_s *mpq_a; MPQArchive(const char* filename); + ~MPQArchive() { close(); } void close(); void GetFileListTo(vector<string>& filelist) { diff --git a/src/tools/mmaps_generator/MapBuilder.cpp b/src/tools/mmaps_generator/MapBuilder.cpp index 06a764690ca..a8254eb5eaf 100644 --- a/src/tools/mmaps_generator/MapBuilder.cpp +++ b/src/tools/mmaps_generator/MapBuilder.cpp @@ -202,7 +202,10 @@ namespace MMAP minX = INT_MIN; minY = INT_MIN; - float bmin[3], bmax[3], lmin[3], lmax[3]; + float bmin[3] = { 0, 0, 0 }; + float bmax[3] = { 0, 0, 0 }; + float lmin[3] = { 0, 0, 0 }; + float lmax[3] = { 0, 0, 0 }; MeshData meshData; // make sure we process maps which don't have tiles @@ -260,25 +263,45 @@ namespace MMAP uint32 verticesCount, indicesCount; if (fread(&verticesCount, sizeof(uint32), 1, file) != 1) + { + fclose(file); return; + } + if (fread(&indicesCount, sizeof(uint32), 1, file) != 1) + { + fclose(file); return; + } float* verts = new float[verticesCount]; int* inds = new int[indicesCount]; if (fread(verts, sizeof(float), verticesCount, file) != verticesCount) + { + fclose(file); + delete[] verts; + delete[] inds; return; + } + if (fread(inds, sizeof(int), indicesCount, file) != indicesCount) + { + fclose(file); + delete[] verts; + delete[] inds; return; + } MeshData data; for (uint32 i = 0; i < verticesCount; ++i) data.solidVerts.append(verts[i]); + delete[] verts; for (uint32 i = 0; i < indicesCount; ++i) data.solidTris.append(inds[i]); + delete[] inds; TerrainBuilder::cleanVertices(data.solidVerts, data.solidTris); // get bounds of current tile @@ -659,6 +682,9 @@ namespace MMAP if (!iv.polyMesh) { printf("%s alloc iv.polyMesh FIALED!\n", tileString); + delete[] pmmerge; + delete[] dmmerge; + delete[] tiles; return; } rcMergePolyMeshes(m_rcContext, pmmerge, nmerge, *iv.polyMesh); @@ -667,6 +693,9 @@ namespace MMAP if (!iv.polyMeshDetail) { printf("%s alloc m_dmesh FIALED!\n", tileString); + delete[] pmmerge; + delete[] dmmerge; + delete[] tiles; return; } rcMergePolyMeshDetails(m_rcContext, dmmerge, nmerge, *iv.polyMeshDetail); @@ -674,7 +703,6 @@ namespace MMAP // free things up delete[] pmmerge; delete[] dmmerge; - delete[] tiles; // set polygons as walkable diff --git a/src/tools/mmaps_generator/PathCommon.h b/src/tools/mmaps_generator/PathCommon.h index 3e06ff58410..94a11e01730 100644 --- a/src/tools/mmaps_generator/PathCommon.h +++ b/src/tools/mmaps_generator/PathCommon.h @@ -114,7 +114,6 @@ namespace MMAP const char *p = dirpath.c_str(); DIR * dirp = opendir(p); struct dirent * dp; - dirp = opendir(p); while (dirp) { diff --git a/src/tools/vmap4_assembler/VMapAssembler.cpp b/src/tools/vmap4_assembler/VMapAssembler.cpp index bb8e324bc75..4ee6f5fce3c 100644 --- a/src/tools/vmap4_assembler/VMapAssembler.cpp +++ b/src/tools/vmap4_assembler/VMapAssembler.cpp @@ -5,9 +5,8 @@ int main(int argc, char* argv[]) { - if(argc != 3) + if (argc != 3) { - //printf("\nusage: %s <raw data dir> <vmap dest dir> [config file name]\n", argv[0]); std::cout << "usage: " << argv[0] << " <raw data dir> <vmap dest dir>" << std::endl; return 1; } @@ -19,7 +18,7 @@ int main(int argc, char* argv[]) VMAP::TileAssembler* ta = new VMAP::TileAssembler(src, dest); - if(!ta->convertWorld2()) + if (!ta->convertWorld2()) { std::cout << "exit with errors" << std::endl; delete ta; diff --git a/src/tools/vmap4_extractor/gameobject_extract.cpp b/src/tools/vmap4_extractor/gameobject_extract.cpp index 8a1f67cd2c2..30cedfe7987 100644 --- a/src/tools/vmap4_extractor/gameobject_extract.cpp +++ b/src/tools/vmap4_extractor/gameobject_extract.cpp @@ -49,7 +49,13 @@ void ExtractGameobjectModels() basepath += "/"; std::string path; - FILE * model_list = fopen((basepath + "temp_gameobject_models").c_str(), "wb"); + std::string modelListPath = basepath + "temp_gameobject_models"; + FILE* model_list = fopen(modelListPath.c_str(), "wb"); + if (!model_list) + { + printf("Fatal error: Could not open file %s\n", modelListPath.c_str()); + return; + } for (DBCFile::Iterator it = dbc.begin(); it != dbc.end(); ++it) { diff --git a/src/tools/vmap4_extractor/vmapexport.cpp b/src/tools/vmap4_extractor/vmapexport.cpp index 89e4b850dac..82270cfaa50 100644 --- a/src/tools/vmap4_extractor/vmapexport.cpp +++ b/src/tools/vmap4_extractor/vmapexport.cpp @@ -158,16 +158,16 @@ bool ExtractSingleWmo(std::string& fname) return true; int p = 0; - //Select root wmo files + // Select root wmo files char const* rchr = strrchr(plain_name, '_'); - if(rchr != NULL) + if (rchr != NULL) { char cpy[4]; - strncpy((char*)cpy, rchr, 4); + memcpy(cpy, rchr, 4); for (int i = 0; i < 4; ++i) { int m = cpy[i]; - if(isdigit(m)) + if (isdigit(m)) p++; } } diff --git a/src/tools/vmap4_extractor/wmo.cpp b/src/tools/vmap4_extractor/wmo.cpp index d7bd9ecd2f9..57161cb495a 100644 --- a/src/tools/vmap4_extractor/wmo.cpp +++ b/src/tools/vmap4_extractor/wmo.cpp @@ -136,14 +136,12 @@ bool WMORoot::ConvertToVMAPRootWmo(FILE* pOutfile) return true; } -WMORoot::~WMORoot() -{ -} - WMOGroup::WMOGroup(const std::string &filename) : filename(filename), MOPY(0), MOVI(0), MoviEx(0), MOVT(0), MOBA(0), MobaEx(0), hlq(0), LiquEx(0), LiquBytes(0), groupName(0), descGroupName(0), mogpFlags(0), - mopy_size(0), moba_size(0), LiquEx_size(0), nVertices(0), nTriangles(0) + mopy_size(0), moba_size(0), LiquEx_size(0), nVertices(0), nTriangles(0), + moprIdx(0), moprNItems(0), nBatchA(0), nBatchB(0), fogIdx(0), liquidType(0), + groupWMOID(0), liquflags(0) { memset(bbcorn1, 0, sizeof(bbcorn1)); memset(bbcorn2, 0, sizeof(bbcorn2)); @@ -439,7 +437,7 @@ int WMOGroup::ConvertToVMAPGroupWmo(FILE *output, WMORoot *rootWMO, bool precise if (liquidEntry && liquidEntry < 21) { - switch (((uint8)liquidEntry - 1) & 3) + switch ((liquidEntry - 1) & 3) { case 0: liquidEntry = ((mogpFlags & 0x80000) != 0) + 13; @@ -453,8 +451,6 @@ int WMOGroup::ConvertToVMAPGroupWmo(FILE *output, WMORoot *rootWMO, bool precise case 3: liquidEntry = 20; break; - default: - break; } } @@ -488,7 +484,7 @@ WMOGroup::~WMOGroup() } WMOInstance::WMOInstance(MPQFile& f, char const* WmoInstName, uint32 mapID, uint32 tileX, uint32 tileY, FILE* pDirfile) - : currx(0), curry(0), wmo(NULL), doodadset(0), pos(), indx(0), d3(0) + : currx(0), curry(0), wmo(NULL), doodadset(0), pos(), indx(0), id(0), d2(0), d3(0) { float ff[3]; f.read(&id, 4); diff --git a/src/tools/vmap4_extractor/wmo.h b/src/tools/vmap4_extractor/wmo.h index d0333265851..fe6cef03655 100644 --- a/src/tools/vmap4_extractor/wmo.h +++ b/src/tools/vmap4_extractor/wmo.h @@ -53,7 +53,6 @@ public: float bbcorn2[3]; WMORoot(std::string& filename); - ~WMORoot(); bool open(); bool ConvertToVMAPRootWmo(FILE* output); |