diff options
author | Haru <haru@dotalux.com> | 2015-10-21 05:34:06 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2015-10-21 13:08:11 +0200 |
commit | 8b198db1e0ccc8209b7bcf54b4df62d4747f75b2 (patch) | |
tree | ac63b546e0c532423eaf8ad21a1aa93e9035decc /src/common/console.c | |
parent | b993924a4b5e82f3961d6b5a579c0204c9e36809 (diff) | |
download | hercules-8b198db1e0ccc8209b7bcf54b4df62d4747f75b2.tar.gz hercules-8b198db1e0ccc8209b7bcf54b4df62d4747f75b2.tar.bz2 hercules-8b198db1e0ccc8209b7bcf54b4df62d4747f75b2.tar.xz hercules-8b198db1e0ccc8209b7bcf54b4df62d4747f75b2.zip |
Fixed a console command parse issue
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common/console.c')
-rw-r--r-- | src/common/console.c | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/src/common/console.c b/src/common/console.c index f4f18b799..477141b48 100644 --- a/src/common/console.c +++ b/src/common/console.c @@ -362,7 +362,6 @@ void console_parse_sub(char *line) char *tok; char sublist[CP_CMD_LENGTH * 5]; int i; - unsigned int len = 0; memcpy(bline, line, 200); tok = strtok(line, " "); @@ -375,19 +374,15 @@ void console_parse_sub(char *line) cmd = VECTOR_INDEX(console->input->command_list, i); - len += snprintf(sublist,CP_CMD_LENGTH * 5,"%s", cmd->cmd); + snprintf(sublist, sizeof(sublist), "%s", cmd->cmd); if (cmd->type == CPET_FUNCTION) { - char *r = NULL; - if( (tok = strtok(NULL, " ")) ) { - r = bline; - r += len + 1; - } - cmd->u.func(r); + tok = strtok(NULL, ""); + cmd->u.func(tok); return; } - while (( tok = strtok(NULL, " ") ) != NULL) { + while ((tok = strtok(NULL, " ")) != NULL) { struct CParseEntry *entry = NULL; Assert_retv(cmd->type == CPET_CATEGORY); @@ -409,17 +404,15 @@ void console_parse_sub(char *line) } entry = VECTOR_INDEX(cmd->u.children, i); if (entry->type == CPET_FUNCTION) { - char *r = NULL; - if ((tok = strtok(NULL, " "))) { - r = bline; - r += len + strlen(entry->cmd) + 1; - } - entry->u.func(r); + tok = strtok(NULL, ""); + entry->u.func(tok); return; } cmd = entry; - len += snprintf(sublist + len,(CP_CMD_LENGTH * 5) - len," %s", cmd->cmd); + + if (strlen(sublist) < sizeof(sublist)-1) + snprintf(sublist+strlen(sublist), sizeof(sublist), " %s", cmd->cmd); } ShowError("Is only a category, type '"CL_WHITE"%s help"CL_RESET"' to list its subcommands\n",sublist); } |