]> granicus.if.org Git - vim/commitdiff
patch 9.0.0020: with some completion reading past end of string v9.0.0020
authorBram Moolenaar <Bram@vim.org>
Fri, 1 Jul 2022 18:58:30 +0000 (19:58 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 1 Jul 2022 18:58:30 +0000 (19:58 +0100)
Problem:    With some completion reading past end of string.
Solution:   Check the length of the string.

src/insexpand.c
src/testdir/test_ins_complete.vim
src/version.c

index 4a5feac9dc1f71b4c11fc6b4fdee7d8bf0b8516a..734550ffd231f7f145d555a441783a39e1fa004a 100644 (file)
@@ -2209,11 +2209,21 @@ ins_compl_stop(int c, int prev_mode, int retval)
     // but only do this, if the Popup is still visible
     if (c == Ctrl_E)
     {
+       char_u *p = NULL;
+
        ins_compl_delete();
        if (compl_leader != NULL)
-           ins_bytes(compl_leader + get_compl_len());
+           p = compl_leader;
        else if (compl_first_match != NULL)
-           ins_bytes(compl_orig_text + get_compl_len());
+           p = compl_orig_text;
+       if (p != NULL)
+       {
+           int     compl_len = get_compl_len();
+           int     len = (int)STRLEN(p);
+
+           if (len > compl_len)
+               ins_bytes_len(p + compl_len, len - compl_len);
+       }
        retval = TRUE;
     }
 
index 365c646a19c652bd945ac8d85a691dd018d86cf9..20c2b4f48f4142b5f5f042c24252291b9d12fa6d 100644 (file)
@@ -2184,4 +2184,12 @@ func Test_complete_smartindent()
   delfunction! FooBarComplete
 endfunc
 
+func Test_complete_overrun()
+  " this was going past the end of the copied text
+  new
+  sil norm si\94\140\ 3s\ f0\18\f\ 5
+  bwipe!
+endfunc
+
+
 " vim: shiftwidth=2 sts=2 expandtab
index 42e9135e1f6d09cda0cbee80326ee3ab746bad9a..26cb768a8254171483b05491c9bfdc32ee4f0e4b 100644 (file)
@@ -735,6 +735,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    20,
 /**/
     19,
 /**/