Skip to content

Commit 8ac0f73

Browse files
John Marriottchrisbra
authored andcommitted
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>
1 parent a3a7d10 commit 8ac0f73

4 files changed

Lines changed: 25 additions & 31 deletions

File tree

src/edit.c

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,11 +2916,11 @@ stuff_inserted(
29162916
long count, // Repeat this many times
29172917
int no_esc) // Don't add an ESC at the end
29182918
{
2919-
string_T *insert; // text to be inserted
2919+
string_T insert; // text to be inserted
29202920
char_u last = ' ';
29212921

29222922
insert = get_last_insert();
2923-
if (insert->string == NULL)
2923+
if (insert.string == NULL)
29242924
{
29252925
emsg(_(e_no_inserted_text_yet));
29262926
return FAIL;
@@ -2930,39 +2930,39 @@ stuff_inserted(
29302930
if (c != NUL)
29312931
stuffcharReadbuff(c);
29322932

2933-
if (insert->length > 0)
2933+
if (insert.length > 0)
29342934
{
29352935
char_u *p;
29362936

29372937
// look for the last ESC in 'insert'
2938-
for (p = insert->string + insert->length - 1; p >= insert->string; --p)
2938+
for (p = insert.string + insert.length - 1; p >= insert.string; --p)
29392939
{
29402940
if (*p == ESC)
29412941
{
2942-
insert->length = (size_t)(p - insert->string);
2942+
insert.length = (size_t)(p - insert.string);
29432943
break;
29442944
}
29452945
}
29462946
}
29472947

2948-
if (insert->length > 0)
2948+
if (insert.length > 0)
29492949
{
2950-
char_u *p = insert->string + insert->length - 1;
2950+
char_u *p = insert.string + insert.length - 1;
29512951

29522952
// when the last char is either "0" or "^" it will be quoted if no ESC
29532953
// comes after it OR if it will insert more than once and "ptr"
29542954
// starts with ^D. -- Acevedo
29552955
if ((*p == '0' || *p == '^')
2956-
&& (no_esc || (*insert->string == Ctrl_D && count > 1)))
2956+
&& (no_esc || (*insert.string == Ctrl_D && count > 1)))
29572957
{
29582958
last = *p;
2959-
--insert->length;
2959+
--insert.length;
29602960
}
29612961
}
29622962

29632963
do
29642964
{
2965-
stuffReadbuffLen(insert->string, insert->length);
2965+
stuffReadbuffLen(insert.string, insert.length);
29662966
// a trailing "0" is inserted as "<C-V>048", "^" as "<C-V>^"
29672967
switch (last)
29682968
{
@@ -2991,23 +2991,18 @@ stuff_inserted(
29912991
return OK;
29922992
}
29932993

2994-
string_T *
2994+
string_T
29952995
get_last_insert(void)
29962996
{
2997-
static string_T insert = {NULL, 0};
2997+
string_T insert = {NULL, 0};
29982998

2999-
if (last_insert.string == NULL)
3000-
{
3001-
insert.string = NULL;
3002-
insert.length = 0;
3003-
}
3004-
else
2999+
if (last_insert.string != NULL)
30053000
{
30063001
insert.string = last_insert.string + last_insert_skip;
30073002
insert.length = (size_t)(last_insert.length - last_insert_skip);
30083003
}
30093004

3010-
return &insert;
3005+
return insert;
30113006
}
30123007

30133008
/*
@@ -3017,22 +3012,17 @@ get_last_insert(void)
30173012
char_u *
30183013
get_last_insert_save(void)
30193014
{
3020-
string_T *insert = get_last_insert();
3015+
string_T insert = get_last_insert();
30213016
char_u *s;
30223017

3023-
if (insert->string == NULL)
3018+
if (insert.string == NULL)
30243019
return NULL;
3025-
s = vim_strnsave(insert->string, insert->length);
3020+
s = vim_strnsave(insert.string, insert.length);
30263021
if (s == NULL)
30273022
return NULL;
30283023

3029-
if (insert->length > 0)
3030-
{
3031-
// remove trailing ESC
3032-
--insert->length;
3033-
if (s[insert->length] == ESC)
3034-
s[insert->length] = NUL;
3035-
}
3024+
if (insert.length > 0 && s[insert.length - 1] == ESC) // remove trailing ESC
3025+
s[insert.length - 1] = NUL;
30363026
return s;
30373027
}
30383028

src/proto/edit.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int cursor_up(long n, int upd_topline);
2424
void cursor_down_inner(win_T *wp, long n);
2525
int cursor_down(long n, int upd_topline);
2626
int stuff_inserted(int c, long count, int no_esc);
27-
string_T *get_last_insert(void);
27+
string_T get_last_insert(void);
2828
char_u *get_last_insert_save(void);
2929
void replace_push(int c);
3030
int replace_push_mb(char_u *p);

src/register.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2379,6 +2379,7 @@ ex_display(exarg_T *eap)
23792379
char_u *arg = eap->arg;
23802380
int clen;
23812381
int type;
2382+
string_T insert;
23822383

23832384
if (arg != NULL && *arg == NUL)
23842385
arg = NULL;
@@ -2471,7 +2472,8 @@ ex_display(exarg_T *eap)
24712472
}
24722473

24732474
// display last inserted text
2474-
if ((p = get_last_insert()->string) != NULL
2475+
insert = get_last_insert();
2476+
if ((p = insert.string) != NULL
24752477
&& (arg == NULL || vim_strchr(arg, '.') != NULL) && !got_int
24762478
&& !message_filtered(p))
24772479
{

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1222,
707709
/**/
708710
1221,
709711
/**/

0 commit comments

Comments
 (0)