aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-08-27 06:50:55 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-08-27 07:03:07 +0800
commit608134794d2a039358825396b860a7f432c1a4bd (patch)
tree2a6d4599e7549786d624756ac8d6e4cfd46fce83
parent2676555b229feae462df32bf6dfce7f234b7be53 (diff)
downloadrneovim-608134794d2a039358825396b860a7f432c1a4bd.tar.gz
rneovim-608134794d2a039358825396b860a7f432c1a4bd.tar.bz2
rneovim-608134794d2a039358825396b860a7f432c1a4bd.zip
vim-patch:9.0.0284: using static buffer for multiple completion functions
Problem: Using static buffer for multiple completion functions. Solution: Use one buffer in expand_T. https://github.com/vim/vim/commit/5ff595d9db2d9a33aa10cc9f18f256826226862f
-rw-r--r--src/nvim/cmdhist.c12
-rw-r--r--src/nvim/ex_cmds_defs.h2
-rw-r--r--src/nvim/os/env.c7
-rw-r--r--src/nvim/syntax.c7
4 files changed, 12 insertions, 16 deletions
diff --git a/src/nvim/cmdhist.c b/src/nvim/cmdhist.c
index b078fc6570..1426054d0b 100644
--- a/src/nvim/cmdhist.c
+++ b/src/nvim/cmdhist.c
@@ -90,14 +90,14 @@ static char *(history_names[]) = {
/// arguments of the ":history command.
char *get_history_arg(expand_T *xp, int idx)
{
- static char_u compl[2] = { NUL, NUL };
- char *short_names = ":=@>?/";
- int short_names_count = (int)STRLEN(short_names);
- int history_name_count = ARRAY_SIZE(history_names) - 1;
+ const char *short_names = ":=@>?/";
+ const int short_names_count = (int)STRLEN(short_names);
+ const int history_name_count = ARRAY_SIZE(history_names) - 1;
if (idx < short_names_count) {
- compl[0] = (char_u)short_names[idx];
- return (char *)compl;
+ xp->xp_buf[0] = short_names[idx];
+ xp->xp_buf[1] = NUL;
+ return xp->xp_buf;
}
if (idx < short_names_count + history_name_count) {
return history_names[idx - short_names_count];
diff --git a/src/nvim/ex_cmds_defs.h b/src/nvim/ex_cmds_defs.h
index 5d8ed64c60..71956b2246 100644
--- a/src/nvim/ex_cmds_defs.h
+++ b/src/nvim/ex_cmds_defs.h
@@ -237,6 +237,8 @@ struct expand {
int xp_col; // cursor position in line
char **xp_files; // list of files
char *xp_line; // text being completed
+#define EXPAND_BUF_LEN 256
+ char xp_buf[EXPAND_BUF_LEN]; // buffer for returned match
};
// values for xp_backslash
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index d46d51882e..ea9a803a86 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -1156,15 +1156,12 @@ char *home_replace_save(buf_T *buf, const char *src)
/// Function given to ExpandGeneric() to obtain an environment variable name.
char *get_env_name(expand_T *xp, int idx)
{
-#define ENVNAMELEN 100
- // this static buffer is needed to avoid a memory leak in ExpandGeneric
- static char_u name[ENVNAMELEN];
assert(idx >= 0);
char *envname = os_getenvname_at_index((size_t)idx);
if (envname) {
- STRLCPY(name, envname, ENVNAMELEN);
+ STRLCPY(xp->xp_buf, envname, EXPAND_BUF_LEN);
xfree(envname);
- return (char *)name;
+ return xp->xp_buf;
}
return NULL;
}
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index de8d5ef638..20287089f7 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -5737,9 +5737,6 @@ void set_context_in_syntax_cmd(expand_T *xp, const char *arg)
*/
char *get_syntax_name(expand_T *xp, int idx)
{
-#define CBUFFER_LEN 256
- static char cbuffer[CBUFFER_LEN]; // TODO: better solution
-
switch (expand_what) {
case EXP_SUBCMD:
return subcommands[idx].name;
@@ -5761,9 +5758,9 @@ char *get_syntax_name(expand_T *xp, int idx)
}
case EXP_CLUSTER:
if (idx < curwin->w_s->b_syn_clusters.ga_len) {
- vim_snprintf(cbuffer, CBUFFER_LEN, "@%s",
+ vim_snprintf(xp->xp_buf, EXPAND_BUF_LEN, "@%s",
SYN_CLSTR(curwin->w_s)[idx].scl_name);
- return cbuffer;
+ return xp->xp_buf;
} else {
return NULL;
}