]> granicus.if.org Git - vim/commitdiff
patch 9.0.0284: using static buffer for multiple completion functions v9.0.0284
authorBram Moolenaar <Bram@vim.org>
Fri, 26 Aug 2022 21:36:41 +0000 (22:36 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 26 Aug 2022 21:36:41 +0000 (22:36 +0100)
Problem:    Using static buffer for multiple completion functions.
Solution:   Use one buffer in expand_T.

src/cmdhist.c
src/misc1.c
src/structs.h
src/syntax.c
src/version.c

index 6256fd91b09608721aff5f92680c39dacb0e815e..0619e827759b07402b21cf1649f14603cfa0046a 100644 (file)
@@ -99,15 +99,15 @@ static char *(history_names[]) =
     char_u *
 get_history_arg(expand_T *xp UNUSED, 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_LENGTH(history_names) - 1;
+    char    *short_names = ":=@>?/";
+    int            short_names_count = (int)STRLEN(short_names);
+    int            history_name_count = ARRAY_LENGTH(history_names) - 1;
 
     if (idx < short_names_count)
     {
-       compl[0] = (char_u)short_names[idx];
-       return compl;
+       xp->xp_buf[0] = (char_u)short_names[idx];
+       xp->xp_buf[1] = NUL;
+       return xp->xp_buf;
     }
     if (idx < short_names_count + history_name_count)
        return (char_u *)history_names[idx - short_names_count];
index 638392252166271023539bcbb46f193a7f20301b..e8216a08aec8d2f04f5f906eb0f36ace5365b555 100644 (file)
@@ -2016,18 +2016,14 @@ get_env_name(
     expand_T   *xp UNUSED,
     int                idx)
 {
-# if defined(AMIGA)
-    /*
-     * No environ[] on the Amiga.
-     */
+#if defined(AMIGA)
+    // No environ[] on the Amiga.
     return NULL;
-# else
+#else
 # ifndef __WIN32__
     // Borland C++ 5.2 has this in a header file.
     extern char                **environ;
 # endif
-# define ENVNAMELEN 100
-    static char_u      name[ENVNAMELEN];
     char_u             *str;
     int                        n;
 
@@ -2035,15 +2031,15 @@ get_env_name(
     if (str == NULL)
        return NULL;
 
-    for (n = 0; n < ENVNAMELEN - 1; ++n)
+    for (n = 0; n < EXPAND_BUF_LEN - 1; ++n)
     {
        if (str[n] == '=' || str[n] == NUL)
            break;
-       name[n] = str[n];
+       xp->xp_buf[n] = str[n];
     }
-    name[n] = NUL;
-    return name;
-# endif
+    xp->xp_buf[n] = NUL;
+    return xp->xp_buf;
+#endif
 }
 
 /*
index 28cfa00ffc205ad1da906d7506352bf78a43db4f..fc44d23a64a94bdc9ff12103238e4679e34b9b68 100644 (file)
@@ -598,6 +598,8 @@ typedef struct expand
     int                xp_col;                 // cursor position in line
     char_u     **xp_files;             // list of files
     char_u     *xp_line;               // text being completed
+#define EXPAND_BUF_LEN 256
+    char_u     xp_buf[EXPAND_BUF_LEN]; // buffer for returned match
 } expand_T;
 
 /*
index 1fc205414e00f9c69ca87fe4f2ba4cee1e2b4042..c68e001be916e723ed5ad0fe4ae172b83f7e5132 100644 (file)
@@ -6420,11 +6420,8 @@ set_context_in_syntax_cmd(expand_T *xp, char_u *arg)
  * expansion.
  */
     char_u *
-get_syntax_name(expand_T *xp UNUSED, int idx)
+get_syntax_name(expand_T *xp, int idx)
 {
-#define CBUFFER_LEN 256
-    static char_u      cbuffer[CBUFFER_LEN]; // TODO: better solution
-
     switch (expand_what)
     {
        case EXP_SUBCMD:
@@ -6452,9 +6449,9 @@ get_syntax_name(expand_T *xp UNUSED, int idx)
        {
            if (idx < curwin->w_s->b_syn_clusters.ga_len)
            {
-               vim_snprintf((char *)cbuffer, CBUFFER_LEN, "@%s",
+               vim_snprintf((char *)xp->xp_buf, EXPAND_BUF_LEN, "@%s",
                                         SYN_CLSTR(curwin->w_s)[idx].scl_name);
-               return cbuffer;
+               return xp->xp_buf;
            }
            else
                return NULL;
index c3fbe5f591099b34dc1c0d943206aa315aadc586..2e4868744766e686157cdbc91d55a052fd3d7c66 100644 (file)
@@ -707,6 +707,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    284,
 /**/
     283,
 /**/