Scripts/Commands: Fix a crash in .help - closes #25360

(cherry picked from commit 944f49d613)
This commit is contained in:
Treeston
2020-08-30 13:45:04 +02:00
committed by Shauren
parent 45e9e94311
commit a65e7e0213
2 changed files with 11 additions and 9 deletions

View File

@@ -159,7 +159,7 @@ bool ChatHandler::hasStringAbbr(const char* name, const char* part)
while (true)
{
if (!*part)
if (!*part || *part == ' ')
return true;
else if (!*name)
return false;
@@ -461,6 +461,10 @@ bool ChatHandler::ShowHelpForCommand(std::vector<ChatCommand> const& table, cons
{
if (*cmd)
{
std::string subcmd;
if (size_t n = std::string_view(cmd).find(' '); n != std::string_view::npos)
subcmd.assign(cmd+n+1);
for (uint32 i = 0; i < table.size(); ++i)
{
// must be available (ignore handler existence to show command with possible available subcommands)
@@ -471,11 +475,9 @@ bool ChatHandler::ShowHelpForCommand(std::vector<ChatCommand> const& table, cons
continue;
// have subcommand
char const* subcmd = (*cmd) ? strtok(nullptr, " ") : "";
if (!table[i].ChildCommands.empty() && subcmd && *subcmd)
if (!table[i].ChildCommands.empty() && !subcmd.empty())
{
if (ShowHelpForCommand(table[i].ChildCommands, subcmd))
if (ShowHelpForCommand(table[i].ChildCommands, subcmd.c_str()))
return true;
}
@@ -483,7 +485,7 @@ bool ChatHandler::ShowHelpForCommand(std::vector<ChatCommand> const& table, cons
SendSysMessage(table[i].Help.c_str());
if (!table[i].ChildCommands.empty())
if (ShowHelpForSubCommands(table[i].ChildCommands, table[i].Name, subcmd ? subcmd : ""))
if (ShowHelpForSubCommands(table[i].ChildCommands, table[i].Name, subcmd.c_str()))
return true;
return !table[i].Help.empty();