]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1222: using wrong length for last inserted string v9.1.1222
authorJohn Marriott <basilisk@internode.on.net>
Tue, 18 Mar 2025 19:49:01 +0000 (20:49 +0100)
committerChristian Brabandt <cb@256bit.org>
Tue, 18 Mar 2025 19:49:01 +0000 (20:49 +0100)
Problem:  using wrong length for last inserted string
          (Christ van Willegen, after v9.1.1212)
Solution: use the correct length in get_last_insert_save(), make
          get_last_insert() return a string_T (John Marriott)

closes: #16921

Signed-off-by: John Marriott <basilisk@internode.on.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/edit.c
src/proto/edit.pro
src/register.c
src/version.c

index 143a4ce3ca98866bc080039c01266ff16c309d6c..a2a004c12413f094829d8a87be731decd40d6960 100644 (file)
@@ -2916,11 +2916,11 @@ stuff_inserted(
     long    count,     // Repeat this many times
     int            no_esc)     // Don't add an ESC at the end
 {
-    string_T   *insert;                                // text to be inserted
+    string_T   insert;                         // text to be inserted
     char_u     last = ' ';
 
     insert = get_last_insert();
-    if (insert->string == NULL)
+    if (insert.string == NULL)
     {
        emsg(_(e_no_inserted_text_yet));
        return FAIL;
@@ -2930,39 +2930,39 @@ stuff_inserted(
     if (c != NUL)
        stuffcharReadbuff(c);
 
-    if (insert->length > 0)
+    if (insert.length > 0)
     {
        char_u  *p;
 
        // look for the last ESC in 'insert'
-       for (p = insert->string + insert->length - 1; p >= insert->string; --p)
+       for (p = insert.string + insert.length - 1; p >= insert.string; --p)
        {
            if (*p == ESC)
            {
-               insert->length = (size_t)(p - insert->string);
+               insert.length = (size_t)(p - insert.string);
                break;
            }
        }
     }
 
-    if (insert->length > 0)
+    if (insert.length > 0)
     {
-       char_u  *p = insert->string + insert->length - 1;
+       char_u  *p = insert.string + insert.length - 1;
 
        // when the last char is either "0" or "^" it will be quoted if no ESC
        // comes after it OR if it will insert more than once and "ptr"
        // starts with ^D.      -- Acevedo
        if ((*p == '0' || *p == '^')
-               && (no_esc || (*insert->string == Ctrl_D && count > 1)))
+               && (no_esc || (*insert.string == Ctrl_D && count > 1)))
        {
            last = *p;
-           --insert->length;
+           --insert.length;
        }
     }
 
     do
     {
-       stuffReadbuffLen(insert->string, insert->length);
+       stuffReadbuffLen(insert.string, insert.length);
        // a trailing "0" is inserted as "<C-V>048", "^" as "<C-V>^"
        switch (last)
        {
@@ -2991,23 +2991,18 @@ stuff_inserted(
     return OK;
 }
 
-    string_T *
+    string_T
 get_last_insert(void)
 {
-    static string_T insert = {NULL, 0};
+    string_T insert = {NULL, 0};
 
-    if (last_insert.string == NULL)
-    {
-       insert.string = NULL;
-       insert.length = 0;
-    }
-    else
+    if (last_insert.string != NULL)
     {
        insert.string = last_insert.string + last_insert_skip;
        insert.length = (size_t)(last_insert.length - last_insert_skip);
     }
 
-    return &insert;
+    return insert;
 }
 
 /*
@@ -3017,22 +3012,17 @@ get_last_insert(void)
     char_u *
 get_last_insert_save(void)
 {
-    string_T   *insert = get_last_insert();
+    string_T   insert = get_last_insert();
     char_u     *s;
 
-    if (insert->string == NULL)
+    if (insert.string == NULL)
        return NULL;
-    s = vim_strnsave(insert->string, insert->length);
+    s = vim_strnsave(insert.string, insert.length);
     if (s == NULL)
        return NULL;
 
-    if (insert->length > 0)
-    {
-       // remove trailing ESC
-       --insert->length;
-       if (s[insert->length] == ESC)
-           s[insert->length] = NUL;
-    }
+    if (insert.length > 0 && s[insert.length - 1] == ESC)      // remove trailing ESC
+       s[insert.length - 1] = NUL;
     return s;
 }
 
index 170ac978cb5faa0d96e221064d5806d9ba7de470..6b2b75a743083818547c8183c3b2b21a35d46f9a 100644 (file)
@@ -24,7 +24,7 @@ int cursor_up(long n, int upd_topline);
 void cursor_down_inner(win_T *wp, long n);
 int cursor_down(long n, int upd_topline);
 int stuff_inserted(int c, long count, int no_esc);
-string_T *get_last_insert(void);
+string_T get_last_insert(void);
 char_u *get_last_insert_save(void);
 void replace_push(int c);
 int replace_push_mb(char_u *p);
index 1674a1260e844c6a42b873160b044bd55ba652b5..267e0fcc43348d9d7610493fd8c110a31596f3f3 100644 (file)
@@ -2379,6 +2379,7 @@ ex_display(exarg_T *eap)
     char_u     *arg = eap->arg;
     int                clen;
     int                type;
+    string_T   insert;
 
     if (arg != NULL && *arg == NUL)
        arg = NULL;
@@ -2471,7 +2472,8 @@ ex_display(exarg_T *eap)
     }
 
     // display last inserted text
-    if ((p = get_last_insert()->string) != NULL
+    insert = get_last_insert();
+    if ((p = insert.string) != NULL
                  && (arg == NULL || vim_strchr(arg, '.') != NULL) && !got_int
                                                      && !message_filtered(p))
     {
index 12a7f4538e6277959da120b716744d4774d2df9c..ee5b5ed7f31d4c36e158db6b7a4ec5dab125e4f3 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1222,
 /**/
     1221,
 /**/