From 08b77acd8dbc64130feede4f85eb0001c806f165 Mon Sep 17 00:00:00 2001 From: EricksOliveira Date: Mon, 24 Mar 2025 10:57:39 -0300 Subject: [PATCH] Chat: Fix index out of bounds crash in case verb_pos equals zero (#1115) Prevents invalid accesses to the word[] array, preventing possible crashes. Improves the message selection logic in bot chat. Fixes an error in the switch-case structure, ensuring that all possible messages are used correctly. --- src/strategy/actions/SayAction.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/strategy/actions/SayAction.cpp b/src/strategy/actions/SayAction.cpp index 93d36a00..f6a6c316 100644 --- a/src/strategy/actions/SayAction.cpp +++ b/src/strategy/actions/SayAction.cpp @@ -969,7 +969,7 @@ std::string ChatReplyAction::GenerateReplyMessage(Player* bot, std::string& inco msg = "ya %s but thats in the past"; break; case 2: - msg = word[verb_pos - 1] + " will " + word[verb_pos + 1] + " again though %s"; + msg = word[verb_pos ? verb_pos - 1 : verb_pos + 1] + " will " + word[verb_pos + 1] + " again though %s"; break; } msg = std::regex_replace(msg, std::regex("%s"), name); @@ -1013,7 +1013,7 @@ std::string ChatReplyAction::GenerateReplyMessage(Player* bot, std::string& inco msg = "%s, what will happen %s?"; break; case 2: - msg = "are you saying " + word[verb_pos - 1] + " will " + word[verb_pos + 1] + " " + word[verb_pos + 2] + " %s?"; + msg = "are you saying " + word[verb_pos ? verb_pos - 1 : verb_pos + 1] + " will " + word[verb_pos + 1] + " " + word[verb_pos + 2] + " %s?"; break; } msg = std::regex_replace(msg, std::regex("%s"), name);