From 365ae6ff25a288ea83e192066b9cc162a020a844 Mon Sep 17 00:00:00 2001 From: Peter Keresztes Schmidt Date: Mon, 13 Jul 2020 16:35:31 +0200 Subject: Fix some compiler warnings reported by GCC (#25007) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Core/AI: Remove unneeded null checks GetMap() can never return NULL. Fixes additionally -Wunused-variable warnings reported by GCC. * Core/GameObject: Fix a -Wunused-variable warning reported by GCC * Core/Player: Fix a -Wunused-variable warning reported by GCC * Scritps/CavernsOfTime: Fix -Wimplicit-fallthrough warnings reported by GCC * Scritps/CavernsOfTime: Fix a -Wmaybe-uninitialized warning reported by GCC Warning: /home/peterke/DEV/TrinityCore/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/npc_arthas.cpp: In member function ‘virtual void npc_arthas_stratholme::npc_arthas_stratholmeAI::UpdateAI(uint32)’: /home/peterke/DEV/TrinityCore/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/npc_arthas.cpp:1119:58: warning: ‘emote’ may be used uninitialized in this function [-Wmaybe-uninitialized] 1119 | (*it)->HandleEmoteCommand(emote); | ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ * Scritps/PitOfSaron: Fix -Wunused-variable warnings reported by GCC * Scritps/EyeOfEternity: Fix a -Wclass-memaccess warning reported by GCC Warning: /home/peterke/DEV/TrinityCore/src/server/scripts/Northrend/Nexus/EyeOfEternity/boss_malygos.cpp: In member function ‘virtual void boss_malygos::boss_malygosAI::UpdateAI(uint32)’: /home/peterke/DEV/TrinityCore/src/server/scripts/Northrend/Nexus/EyeOfEternity/boss_malygos.cpp:950:81: warning: ‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘class ObjectGuid’; use assignment or value-initialization instead [-Wclass-memaccess] 950 | memset(_surgeTargetGUID, 0, sizeof(_surgeTargetGUID)); | * Scritps/CoilfangReservoir: Fix a -Wclass-memaccess warning reported by GCC Warning: /home/peterke/DEV/TrinityCore/src/server/scripts/Outland/CoilfangReservoir/SerpentShrine/boss_leotheras_the_blind.cpp: In member function ‘void boss_leotheras_the_blind::boss_leotheras_the_blindAI::Initialize()’: /home/peterke/DEV/TrinityCore/src/server/scripts/Outland/CoilfangReservoir/SerpentShrine/boss_leotheras_the_blind.cpp:220:55: warning: ‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘class ObjectGuid’; use assignment or value-initialization instead [-Wclass-memaccess] 220 | memset(InnderDemon, 0, sizeof(InnderDemon)); | ^ * Scritps/Naxx: Fix a -Wimplicit-fallthrough warning reported by GCC For discussion see https://github.com/TrinityCore/TrinityCore/pull/25007 (cherry picked from commit 10be49bdfe6bd1f4d8e0eaf3a1b4354c5a57a2a9) --- src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp | 9 +++---- .../game/AI/ScriptedAI/ScriptedFollowerAI.cpp | 9 +++---- src/server/game/Entities/GameObject/GameObject.cpp | 2 +- src/server/game/Entities/Player/Player.cpp | 2 +- .../BlackrockSpire/instance_blackrock_spire.cpp | 1 + .../boss_salramm_the_fleshcrafter.cpp | 2 +- .../CullingOfStratholme/culling_of_stratholme.cpp | 2 +- .../CullingOfStratholme/npc_arthas.cpp | 31 +++++++--------------- .../PitOfSaron/instance_pit_of_saron.cpp | 4 +-- .../scripts/Northrend/Naxxramas/boss_thaddius.cpp | 1 + 10 files changed, 24 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp index 354d21d5d9f..46085bf79ab 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp @@ -276,13 +276,10 @@ void EscortAI::AddWaypoint(uint32 id, float x, float y, float z, float orientati void EscortAI::Start(bool isActiveAttacker /* = true*/, bool run /* = false */, ObjectGuid playerGUID /* = 0 */, Quest const* quest /* = nullptr */, bool instantRespawn /* = false */, bool canLoopPath /* = false */, bool resetWaypoints /* = true */) { // Queue respawn from the point it starts - if (Map* map = me->GetMap()) + if (CreatureData const* cdata = me->GetCreatureData()) { - if (CreatureData const* cdata = me->GetCreatureData()) - { - if (sWorld->getBoolConfig(CONFIG_RESPAWN_DYNAMIC_ESCORTNPC) && (cdata->spawnGroupData->flags & SPAWNGROUP_FLAG_ESCORTQUESTNPC)) - me->SaveRespawnTime(me->GetRespawnDelay()); - } + if (sWorld->getBoolConfig(CONFIG_RESPAWN_DYNAMIC_ESCORTNPC) && (cdata->spawnGroupData->flags & SPAWNGROUP_FLAG_ESCORTQUESTNPC)) + me->SaveRespawnTime(me->GetRespawnDelay()); } if (me->IsEngaged()) diff --git a/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp index 5846a57f8aa..ab8664c6e01 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp @@ -156,13 +156,10 @@ void FollowerAI::UpdateFollowerAI(uint32 /*uiDiff*/) void FollowerAI::StartFollow(Player* player, uint32 factionForFollower, uint32 quest) { - if (Map* map = me->GetMap()) + if (CreatureData const* cdata = me->GetCreatureData()) { - if (CreatureData const* cdata = me->GetCreatureData()) - { - if (sWorld->getBoolConfig(CONFIG_RESPAWN_DYNAMIC_ESCORTNPC) && (cdata->spawnGroupData->flags & SPAWNGROUP_FLAG_ESCORTQUESTNPC)) - me->SaveRespawnTime(me->GetRespawnDelay()); - } + if (sWorld->getBoolConfig(CONFIG_RESPAWN_DYNAMIC_ESCORTNPC) && (cdata->spawnGroupData->flags & SPAWNGROUP_FLAG_ESCORTQUESTNPC)) + me->SaveRespawnTime(me->GetRespawnDelay()); } if (me->IsEngaged()) diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index 0ee4af88702..b03bba6b4cb 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -769,7 +769,7 @@ void GameObject::Update(uint32 diff) Unit* target = nullptr; /// @todo this hack with search required until GO casting not implemented - if (Unit* owner = GetOwner()) + if (GetOwner()) { // Hunter trap: Search units which are unfriendly to the trap's owner Trinity::NearestAttackableNoTotemUnitInObjectRangeCheck checker(this, radius); diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 05a04187978..321868ba618 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -25376,7 +25376,7 @@ void Player::UpdateVisibleGameobjectsOrSpellClicks() auto clickBounds = sObjectMgr->GetSpellClickInfoMapBounds(obj->GetEntry()); for (auto const& clickPair : clickBounds) { - if (ConditionContainer const* conds = sConditionMgr->GetConditionsForSpellClickEvent(obj->GetEntry(), clickPair.second.spellId)) + if (sConditionMgr->GetConditionsForSpellClickEvent(obj->GetEntry(), clickPair.second.spellId)) { UF::ObjectData::Base objMask; UF::UnitData::Base unitMask; diff --git a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/instance_blackrock_spire.cpp b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/instance_blackrock_spire.cpp index 95ac00118f9..ede6a51d060 100644 --- a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/instance_blackrock_spire.cpp +++ b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/instance_blackrock_spire.cpp @@ -298,6 +298,7 @@ public: if (GetBossState(DATA_DRAGONSPIRE_ROOM) != DONE) Events.ScheduleEvent(EVENT_DARGONSPIRE_ROOM_STORE, 1s); } + break; case DATA_BLACKHAND_INCARCERATOR: for (GuidList::const_iterator itr = _incarceratorList.begin(); itr != _incarceratorList.end(); ++itr) if (Creature* creature = instance->GetCreature(*itr)) diff --git a/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/boss_salramm_the_fleshcrafter.cpp b/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/boss_salramm_the_fleshcrafter.cpp index bf17d74e7ad..075e7315285 100644 --- a/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/boss_salramm_the_fleshcrafter.cpp +++ b/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/boss_salramm_the_fleshcrafter.cpp @@ -110,7 +110,7 @@ class boss_salramm : public CreatureScript break; case EVENT_EXPLODE_GHOUL2: events.ScheduleEvent(EVENT_SUMMON_GHOULS, Seconds(4)); - // intentional missing break + /* fallthrough */ case EVENT_EXPLODE_GHOUL1: Talk(SAY_EXPLODE_GHOUL); DoCastAOE(SPELL_EXPLODE_GHOUL, true); diff --git a/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/culling_of_stratholme.cpp b/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/culling_of_stratholme.cpp index ecae7ab189d..eac319c4191 100644 --- a/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/culling_of_stratholme.cpp +++ b/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/culling_of_stratholme.cpp @@ -361,7 +361,7 @@ class npc_chromie_start : public CreatureScript break; case GOSSIP_OFFSET_SKIP_1: AdvanceDungeonFar(); - // intentional missing break + /* fallthrough */ case GOSSIP_OFFSET_TELEPORT: CloseGossipMenuFor(player); me->CastSpell(player, SPELL_TELEPORT_PLAYER); diff --git a/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/npc_arthas.cpp b/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/npc_arthas.cpp index 9a74bcb0fc7..ffefb1457a9 100644 --- a/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/npc_arthas.cpp +++ b/src/server/scripts/Kalimdor/CavernsOfTime/CullingOfStratholme/npc_arthas.cpp @@ -1095,28 +1095,17 @@ public: me->GetCreatureListWithEntryInGrid(nearbyVictims, urand(0, 1) ? NPC_CITIZEN : NPC_RESIDENT, 60.0f); if (!nearbyVictims.empty()) { - std::list::iterator it = nearbyVictims.begin(); - std::advance(it, urand(0, nearbyVictims.size()-1)); - Emote emote; - switch (urand(0, 3)) + Emote emotes[] = { - case 0: - emote = EMOTE_ONESHOT_TALK; - break; - case 1: - emote = EMOTE_ONESHOT_EXCLAMATION; - break; - case 2: - emote = EMOTE_ONESHOT_RUDE; - break; - case 3: - emote = EMOTE_ONESHOT_ROAR; - break; - default: - break; - } - if ((*it)->IsAlive()) - (*it)->HandleEmoteCommand(emote); + EMOTE_ONESHOT_TALK, + EMOTE_ONESHOT_EXCLAMATION, + EMOTE_ONESHOT_RUDE, + EMOTE_ONESHOT_ROAR + }; + + Creature* victim = Trinity::Containers::SelectRandomContainerElement(nearbyVictims); + if (victim->IsAlive()) + victim->HandleEmoteCommand(Trinity::Containers::SelectRandomContainerElement(emotes)); } break; } diff --git a/src/server/scripts/Northrend/FrozenHalls/PitOfSaron/instance_pit_of_saron.cpp b/src/server/scripts/Northrend/FrozenHalls/PitOfSaron/instance_pit_of_saron.cpp index 12dcb97e494..f2b25d4b3bf 100644 --- a/src/server/scripts/Northrend/FrozenHalls/PitOfSaron/instance_pit_of_saron.cpp +++ b/src/server/scripts/Northrend/FrozenHalls/PitOfSaron/instance_pit_of_saron.cpp @@ -157,7 +157,7 @@ class instance_pit_of_saron : public InstanceMapScript case DATA_GARFROST: if (state == DONE) { - if (Creature* summoner = instance->GetCreature(_garfrostGUID)) + if (instance->GetCreature(_garfrostGUID)) { if (_teamInInstance == ALLIANCE) { @@ -175,7 +175,7 @@ class instance_pit_of_saron : public InstanceMapScript case DATA_TYRANNUS: if (state == DONE) { - if (Creature* summoner = instance->GetCreature(_tyrannusGUID)) + if (instance->GetCreature(_tyrannusGUID)) { if (_teamInInstance == ALLIANCE) { diff --git a/src/server/scripts/Northrend/Naxxramas/boss_thaddius.cpp b/src/server/scripts/Northrend/Naxxramas/boss_thaddius.cpp index 6fad136251b..8aa2e149d2c 100644 --- a/src/server/scripts/Northrend/Naxxramas/boss_thaddius.cpp +++ b/src/server/scripts/Northrend/Naxxramas/boss_thaddius.cpp @@ -402,6 +402,7 @@ struct boss_thaddius : public BossAI break; case EVENT_ENABLE_BALL_LIGHTNING: ballLightningUnlocked = true; + break; case EVENT_ENGAGE: me->SetReactState(REACT_AGGRESSIVE); break; -- cgit v1.2.3