diff options
author | Giacomo Pozzoni <giacomopoz@gmail.com> | 2021-01-24 16:04:47 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2022-03-06 01:35:01 +0100 |
commit | a66b968f91d159b149ef5b7357d8a92572cb0b3c (patch) | |
tree | cf1e221b668b4ae8eacfff856aea06cac4d8d3c5 /src/server/scripts | |
parent | 91d7a8b06954fa8a2e67166f731644dec1f5e687 (diff) |
Core/Misc: Fix static analysis issues (#25924)
* Core/Misc: Fix static analysis issues
* Fix infinite loop in ".debug send opcode"
Fix using uninitialized memory in ".debug send opcode"
(cherry picked from commit 661f554b9e08a3721227f1e4a4fe6fd74e43a1f4)
Diffstat (limited to 'src/server/scripts')
4 files changed, 74 insertions, 35 deletions
diff --git a/src/server/scripts/Commands/cs_debug.cpp b/src/server/scripts/Commands/cs_debug.cpp index 5fc4e46895e..f03829e4642 100644 --- a/src/server/scripts/Commands/cs_debug.cpp +++ b/src/server/scripts/Commands/cs_debug.cpp @@ -330,49 +330,63 @@ public: std::stringstream parsedStream; while (!ifs.eof()) { - char commentToken[2]; + char commentToken[2] = {}; ifs.get(commentToken[0]); - if (commentToken[0] == '/' && !ifs.eof()) + if (ifs.eof()) + break; + if (commentToken[0] == '/') { ifs.get(commentToken[1]); - // /* comment - if (commentToken[1] == '*') + if (!ifs.eof()) { - while (!ifs.eof()) + // /* comment + if (commentToken[1] == '*') { - ifs.get(commentToken[0]); - if (commentToken[0] == '*' && !ifs.eof()) + while (!ifs.eof()) { - ifs.get(commentToken[1]); - if (commentToken[1] == '/') + ifs.get(commentToken[0]); + if (ifs.eof()) break; - else - ifs.putback(commentToken[1]); + if (commentToken[0] == '*') + { + ifs.get(commentToken[1]); + if (ifs.eof()) + break; + if (commentToken[1] == '/') + break; + else + ifs.putback(commentToken[1]); + } } + continue; } - continue; - } - // line comment - else if (commentToken[1] == '/') - { - std::string str; - std::getline(ifs, str); - continue; + // line comment + else if (commentToken[1] == '/') + { + std::string str; + std::getline(ifs, str); + if (ifs.eof()) + break; + continue; + } + // regular data + else + ifs.putback(commentToken[1]); } - // regular data - else - ifs.putback(commentToken[1]); } parsedStream.put(commentToken[0]); } ifs.close(); - uint32 opcode; + uint32 opcode = 0; parsedStream >> opcode; + if (!opcode) + return false; + WorldPacket data(OpcodeServer(opcode), 0); - while (!parsedStream.eof()) + while (!parsedStream.eof() && !parsedStream.fail()) { std::string type; parsedStream >> type; @@ -382,38 +396,59 @@ public: if (type == "uint8") { - uint16 val1; + if (parsedStream.eof()) + return false; + uint16 val1 = 0; parsedStream >> val1; + if (parsedStream.fail()) + return false; data << uint8(val1); } else if (type == "uint16") { - uint16 val2; + if (parsedStream.eof()) + return false; + uint16 val2 = 0; parsedStream >> val2; + if (parsedStream.fail()) + return false; data << val2; } else if (type == "uint32") { - uint32 val3; + if (parsedStream.eof()) + return false; + uint32 val3 = 0; parsedStream >> val3; + if (parsedStream.fail()) + return false; data << val3; } else if (type == "uint64") { - uint64 val4; + if (parsedStream.eof()) + return false; + uint64 val4 = 0; parsedStream >> val4; + if (parsedStream.fail()) + return false; data << val4; } else if (type == "float") { - float val5; + if (parsedStream.eof()) + return false; + float val5 = 0.0f; parsedStream >> val5; + if (parsedStream.fail()) + return false; data << val5; } else if (type == "string") { std::string val6; parsedStream >> val6; + // empty string is allowed so no need to check eof/fail here data << val6; } else if (type == "goguid") @@ -423,7 +458,6 @@ public: { handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, "0"); handler->SetSentErrorMessage(true); - ifs.close(); return false; } data << obj->GetGUID(); diff --git a/src/server/scripts/EasternKingdoms/ScarletMonastery/instance_scarlet_monastery.cpp b/src/server/scripts/EasternKingdoms/ScarletMonastery/instance_scarlet_monastery.cpp index 9ddd6aff7a6..256a914b6da 100644 --- a/src/server/scripts/EasternKingdoms/ScarletMonastery/instance_scarlet_monastery.cpp +++ b/src/server/scripts/EasternKingdoms/ScarletMonastery/instance_scarlet_monastery.cpp @@ -25,6 +25,11 @@ #include "ScriptMgr.h" #include "TemporarySummon.h" +Position const BunnySpawnPosition = { 1776.27f, 1348.74f, 19.20f }; +Position const EarthBunnySpawnPosition = { 1765.28f, 1347.46f, 18.55f, 6.17f }; +Position const HeadlessHorsemanSpawnPosition = { 1765.00f, 1347.00f, 15.00f }; +Position const HeadlessHorsemanHeadSpawnPosition = { 1788.54f, 1348.05f, 18.88f }; // Guessed + ObjectData const creatureData[] = { { NPC_HEADLESS_HORSEMAN_HEAD, DATA_HORSEMAN_HEAD }, diff --git a/src/server/scripts/EasternKingdoms/ScarletMonastery/scarlet_monastery.h b/src/server/scripts/EasternKingdoms/ScarletMonastery/scarlet_monastery.h index f25cb46b6b6..27e3fb9b51a 100644 --- a/src/server/scripts/EasternKingdoms/ScarletMonastery/scarlet_monastery.h +++ b/src/server/scripts/EasternKingdoms/ScarletMonastery/scarlet_monastery.h @@ -26,10 +26,10 @@ uint32 const EncounterCount = 9; -Position const BunnySpawnPosition = { 1776.27f, 1348.74f, 19.20f }; -Position const EarthBunnySpawnPosition = { 1765.28f, 1347.46f, 18.55f, 6.17f }; -Position const HeadlessHorsemanSpawnPosition = { 1765.00f, 1347.00f, 15.00f }; -Position const HeadlessHorsemanHeadSpawnPosition = { 1788.54f, 1348.05f, 18.88f }; // Guessed +extern Position const BunnySpawnPosition; +extern Position const EarthBunnySpawnPosition; +extern Position const HeadlessHorsemanSpawnPosition; +extern Position const HeadlessHorsemanHeadSpawnPosition; enum SMDataTypes { diff --git a/src/server/scripts/Northrend/Gundrak/gundrak.h b/src/server/scripts/Northrend/Gundrak/gundrak.h index 18ee2088b90..4e1e51c3ccd 100644 --- a/src/server/scripts/Northrend/Gundrak/gundrak.h +++ b/src/server/scripts/Northrend/Gundrak/gundrak.h @@ -88,7 +88,7 @@ enum GDSpellIds SPELL_FIRE_BEAM_ELEMENTAL = 57072 }; -constexpr Milliseconds TIMER_STATUE_ACTIVATION = 3500ms; +inline constexpr Milliseconds TIMER_STATUE_ACTIVATION = 3500ms; template <class AI, class T> inline AI* GetGundrakAI(T* obj) |