From 72debb6e8365a8d47c4ac2ebd1a9b5a5b619f16e Mon Sep 17 00:00:00 2001 From: EricksOliveira Date: Sat, 19 Oct 2024 09:55:27 -0300 Subject: [PATCH] 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. --- src/ChatHelper.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ChatHelper.cpp b/src/ChatHelper.cpp index 8f464d5d..7bd8e590 100644 --- a/src/ChatHelper.cpp +++ b/src/ChatHelper.cpp @@ -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(); }