diff --git a/src/common/completion.c b/src/common/completion.c index 324fc7f7d..2450dd315 100644 --- a/src/common/completion.c +++ b/src/common/completion.c @@ -118,7 +118,7 @@ completion_get_command_infos (t_completion *completion, char **template, int *max_arg) { t_weechat_alias *ptr_alias; - char *ptr_command, *pos; + char *ptr_command, *ptr_command2, *pos; int i, length; #ifdef PLUGINS t_weechat_plugin *ptr_plugin; @@ -138,11 +138,13 @@ completion_get_command_infos (t_completion *completion, else ptr_command = completion->base_command; - pos = strchr (ptr_command, ' '); + ptr_command2 = strdup (ptr_command); + if (!ptr_command2) + return; + + pos = strchr (ptr_command2, ' '); if (pos) - length = pos - ptr_command; - else - length = strlen (ptr_command); + pos[0] = '\0'; #ifdef PLUGINS /* look for plugin command handler */ @@ -153,11 +155,12 @@ completion_get_command_infos (t_completion *completion, ptr_handler; ptr_handler = ptr_handler->next_handler) { if ((ptr_handler->type == HANDLER_COMMAND) - && (ascii_strncasecmp (ptr_handler->command, - ptr_command, length) == 0)) + && (ascii_strcasecmp (ptr_handler->command, + ptr_command2) == 0)) { *template = ptr_handler->completion_template; *max_arg = MAX_ARGS; + free (ptr_command2); return; } } @@ -167,11 +170,12 @@ completion_get_command_infos (t_completion *completion, /* look for WeeChat internal command */ for (i = 0; weechat_commands[i].command_name; i++) { - if (ascii_strncasecmp (weechat_commands[i].command_name, - ptr_command, length) == 0) + if (ascii_strcasecmp (weechat_commands[i].command_name, + ptr_command2) == 0) { *template = weechat_commands[i].completion_template; *max_arg = weechat_commands[i].max_arg; + free (ptr_command2); return; } } @@ -180,15 +184,17 @@ completion_get_command_infos (t_completion *completion, for (i = 0; irc_commands[i].command_name; i++) { if ((irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg) - && (ascii_strncasecmp (irc_commands[i].command_name, - ptr_command, length) == 0)) + && (ascii_strcasecmp (irc_commands[i].command_name, + ptr_command2) == 0)) { *template = irc_commands[i].completion_template; *max_arg = irc_commands[i].max_arg; + free (ptr_command2); return; } } + free (ptr_command2); return; } diff --git a/weechat/src/common/completion.c b/weechat/src/common/completion.c index 324fc7f7d..2450dd315 100644 --- a/weechat/src/common/completion.c +++ b/weechat/src/common/completion.c @@ -118,7 +118,7 @@ completion_get_command_infos (t_completion *completion, char **template, int *max_arg) { t_weechat_alias *ptr_alias; - char *ptr_command, *pos; + char *ptr_command, *ptr_command2, *pos; int i, length; #ifdef PLUGINS t_weechat_plugin *ptr_plugin; @@ -138,11 +138,13 @@ completion_get_command_infos (t_completion *completion, else ptr_command = completion->base_command; - pos = strchr (ptr_command, ' '); + ptr_command2 = strdup (ptr_command); + if (!ptr_command2) + return; + + pos = strchr (ptr_command2, ' '); if (pos) - length = pos - ptr_command; - else - length = strlen (ptr_command); + pos[0] = '\0'; #ifdef PLUGINS /* look for plugin command handler */ @@ -153,11 +155,12 @@ completion_get_command_infos (t_completion *completion, ptr_handler; ptr_handler = ptr_handler->next_handler) { if ((ptr_handler->type == HANDLER_COMMAND) - && (ascii_strncasecmp (ptr_handler->command, - ptr_command, length) == 0)) + && (ascii_strcasecmp (ptr_handler->command, + ptr_command2) == 0)) { *template = ptr_handler->completion_template; *max_arg = MAX_ARGS; + free (ptr_command2); return; } } @@ -167,11 +170,12 @@ completion_get_command_infos (t_completion *completion, /* look for WeeChat internal command */ for (i = 0; weechat_commands[i].command_name; i++) { - if (ascii_strncasecmp (weechat_commands[i].command_name, - ptr_command, length) == 0) + if (ascii_strcasecmp (weechat_commands[i].command_name, + ptr_command2) == 0) { *template = weechat_commands[i].completion_template; *max_arg = weechat_commands[i].max_arg; + free (ptr_command2); return; } } @@ -180,15 +184,17 @@ completion_get_command_infos (t_completion *completion, for (i = 0; irc_commands[i].command_name; i++) { if ((irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg) - && (ascii_strncasecmp (irc_commands[i].command_name, - ptr_command, length) == 0)) + && (ascii_strcasecmp (irc_commands[i].command_name, + ptr_command2) == 0)) { *template = irc_commands[i].completion_template; *max_arg = irc_commands[i].max_arg; + free (ptr_command2); return; } } + free (ptr_command2); return; }