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

This commit is contained in:
Treeston
2020-08-30 13:45:04 +02:00
parent 2f7d2ef3e9
commit 944f49d613
2 changed files with 11 additions and 9 deletions

View File

@@ -154,7 +154,7 @@ bool ChatHandler::hasStringAbbr(char const* name, char const* part)
while (true)
{
if (!*part)
if (!*part || *part == ' ')
return true;
else if (!*name)
return false;
@@ -456,6 +456,10 @@ bool ChatHandler::ShowHelpForCommand(std::vector<ChatCommand> const& table, char
{
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)
@@ -466,11 +470,9 @@ bool ChatHandler::ShowHelpForCommand(std::vector<ChatCommand> const& table, char
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;
}
@@ -478,7 +480,7 @@ bool ChatHandler::ShowHelpForCommand(std::vector<ChatCommand> const& table, char
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();

View File

@@ -689,16 +689,16 @@ public:
return true;
}
static bool HandleHelpCommand(ChatHandler* handler, Optional<std::string> cmdArg)
static bool HandleHelpCommand(ChatHandler* handler, Tail cmdArg)
{
if (!cmdArg)
if (cmdArg.empty())
{
handler->ShowHelpForCommand(ChatHandler::getCommandTable(), "help");
handler->ShowHelpForCommand(ChatHandler::getCommandTable(), "");
}
else
{
if (!handler->ShowHelpForCommand(ChatHandler::getCommandTable(), cmdArg->c_str()))
if (!handler->ShowHelpForCommand(ChatHandler::getCommandTable(), std::string(cmdArg).c_str()))
handler->SendSysMessage(LANG_NO_HELP_CMD);
}