0
0
mirror of https://github.com/vim/vim.git synced 2025-10-27 09:24:23 -04:00

patch 9.1.1518: getcompletiontype() may crash

Problem:  getcompletiontype() crashes when no completion is available
          (after v9.1.1509).
Solution: Don't call set_expand_context() (zeertzjq)

fixes: #17681
closes: #17684

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq
2025-07-06 20:26:56 +02:00
committed by Christian Brabandt
parent d6a5edd613
commit e2c0f81dd0
8 changed files with 53 additions and 50 deletions

View File

@@ -486,16 +486,33 @@ get_commandtype(int expand)
#ifdef FEAT_EVAL
/*
* Get the name of completion type "expand" as a string.
* 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 or on allocation failure.
*/
char_u *
cmdcomplete_type_to_str(int expand)
cmdcomplete_type_to_str(int expand, char_u *compl_arg)
{
keyvalue_T *kv;
char_u *cmd_compl;
kv = get_commandtype(expand);
if (kv == NULL || kv->value.string == NULL)
return NULL;
return (kv == NULL) ? NULL : kv->value.string;
cmd_compl = kv->value.string;
if (expand == EXPAND_USER_LIST || expand == EXPAND_USER_DEFINED)
{
char_u *buffer;
buffer = alloc(STRLEN(cmd_compl) + STRLEN(compl_arg) + 2);
if (buffer == NULL)
return NULL;
sprintf((char *)buffer, "%s,%s", cmd_compl, compl_arg);
return buffer;
}
return vim_strsave(cmd_compl);
}
/*