mirror of
https://github.com/neovim/neovim.git
synced 2025-09-27 21:48:35 +00:00
vim-patch:9.1.1518: getcompletiontype() may crash (#34819)
Problem: getcompletiontype() crashes when no completion is available
(after v9.1.1509).
Solution: Don't call set_expand_context() (zeertzjq)
fixes: vim/vim#17681
closes: vim/vim#17684
e2c0f81dd0
This commit is contained in:
@@ -403,7 +403,7 @@ char *get_user_cmd_nargs(expand_T *xp, int idx)
|
||||
|
||||
static char *get_command_complete(int arg)
|
||||
{
|
||||
if (arg >= (int)(ARRAY_SIZE(command_complete))) {
|
||||
if (arg < 0 || arg >= (int)(ARRAY_SIZE(command_complete))) {
|
||||
return NULL;
|
||||
}
|
||||
return (char *)command_complete[arg];
|
||||
@@ -422,6 +422,26 @@ char *get_user_cmd_complete(expand_T *xp, int idx)
|
||||
return cmd_compl;
|
||||
}
|
||||
|
||||
/// Get the name of completion type "expand" as an allocated string.
|
||||
/// "compl_arg" is the function name for "custom" and "customlist" types.
|
||||
/// Returns NULL if no completion is available.
|
||||
char *cmdcomplete_type_to_str(int expand, const char *compl_arg)
|
||||
{
|
||||
char *cmd_compl = get_command_complete(expand);
|
||||
if (cmd_compl == NULL || expand == EXPAND_USER_LUA) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (expand == EXPAND_USER_LIST || expand == EXPAND_USER_DEFINED) {
|
||||
size_t buflen = strlen(cmd_compl) + strlen(compl_arg) + 2;
|
||||
char *buffer = xmalloc(buflen);
|
||||
snprintf(buffer, buflen, "%s,%s", cmd_compl, compl_arg);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
return xstrdup(cmd_compl);
|
||||
}
|
||||
|
||||
int cmdcomplete_str_to_type(const char *complete_str)
|
||||
{
|
||||
if (strncmp(complete_str, "custom,", 7) == 0) {
|
||||
|
Reference in New Issue
Block a user