Fix Crash q [ link item ]

This PR adds a null pointer check to the ChatHelper::FormatQuest function to avoid a crash that occurred when trying to format a null quest. The crash occurred when the quest pointer was nullptr and the code tried to access the GetQuestId(), GetQuestLevel() and GetTitle() methods.

Changes:
Added a nullptr check to the beginning of the ChatHelper::FormatQuest function.
Return of a standard error message ("Invalid quest") if the quest is null.

Impact:
Prevents crashes when formatting null quests.
Improves bot system stability when dealing with invalid quests.
This commit is contained in:
EricksOliveira
2024-10-19 09:55:27 -03:00
committed by GitHub
parent b97b6775da
commit 72debb6e83

View File

@@ -304,9 +304,13 @@ ItemIds ChatHelper::parseItems(std::string const text)
std::string const ChatHelper::FormatQuest(Quest const* quest)
{
if (!quest)
{
return "Invalid quest";
}
std::ostringstream out;
out << "|cFFFFFF00|Hquest:" << quest->GetQuestId() << ':' << quest->GetQuestLevel() << "|h[" << quest->GetTitle()
<< "]|h|r";
out << "|cFFFFFF00|Hquest:" << quest->GetQuestId() << ':' << quest->GetQuestLevel() << "|h[" << quest->GetTitle() << "]|h|r";
return out.str();
}