Skip to content

Commit f12129f

Browse files
committed
patch 9.0.0020: with some completion reading past end of string
Problem: With some completion reading past end of string. Solution: Check the length of the string.
1 parent eb273cd commit f12129f

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/insexpand.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,11 +2209,21 @@ ins_compl_stop(int c, int prev_mode, int retval)
22092209
// but only do this, if the Popup is still visible
22102210
if (c == Ctrl_E)
22112211
{
2212+
char_u *p = NULL;
2213+
22122214
ins_compl_delete();
22132215
if (compl_leader != NULL)
2214-
ins_bytes(compl_leader + get_compl_len());
2216+
p = compl_leader;
22152217
else if (compl_first_match != NULL)
2216-
ins_bytes(compl_orig_text + get_compl_len());
2218+
p = compl_orig_text;
2219+
if (p != NULL)
2220+
{
2221+
int compl_len = get_compl_len();
2222+
int len = (int)STRLEN(p);
2223+
2224+
if (len > compl_len)
2225+
ins_bytes_len(p + compl_len, len - compl_len);
2226+
}
22172227
retval = TRUE;
22182228
}
22192229

src/testdir/test_ins_complete.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,4 +2184,12 @@ func Test_complete_smartindent()
21842184
delfunction! FooBarComplete
21852185
endfunc
21862186

2187+
func Test_complete_overrun()
2188+
" this was going past the end of the copied text
2189+
new
2190+
sil norm si”0s0 
2191+
bwipe!
2192+
endfunc
2193+
2194+
21872195
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

736736
static int included_patches[] =
737737
{ /* Add new patch number below this line */
738+
/**/
739+
20,
738740
/**/
739741
19,
740742
/**/

0 commit comments

Comments
 (0)