patch 9.1.1222: using wrong length for last inserted string
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>
diff --git a/src/edit.c b/src/edit.c
index 143a4ce..a2a004c 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -2916,11 +2916,11 @@
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 @@
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 @@
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 @@
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;
}
diff --git a/src/proto/edit.pro b/src/proto/edit.pro
index 170ac97..6b2b75a 100644
--- a/src/proto/edit.pro
+++ b/src/proto/edit.pro
@@ -24,7 +24,7 @@
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);
diff --git a/src/register.c b/src/register.c
index 1674a12..267e0fc 100644
--- a/src/register.c
+++ b/src/register.c
@@ -2379,6 +2379,7 @@
char_u *arg = eap->arg;
int clen;
int type;
+ string_T insert;
if (arg != NULL && *arg == NUL)
arg = NULL;
@@ -2471,7 +2472,8 @@
}
// 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))
{
diff --git a/src/version.c b/src/version.c
index 12a7f45..ee5b5ed 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1222,
+/**/
1221,
/**/
1220,