diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-08-24 16:59:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-24 16:59:03 +0800 |
commit | b0569f5813a019d5fe7a921b9d01f26eb1854b8d (patch) | |
tree | 65fafd01dd8002106ceb00f001b9b4266789dd4f | |
parent | 79f32c20f03965e2733a8c778b8e3478acf9467f (diff) | |
download | rneovim-b0569f5813a019d5fe7a921b9d01f26eb1854b8d.tar.gz rneovim-b0569f5813a019d5fe7a921b9d01f26eb1854b8d.tar.bz2 rneovim-b0569f5813a019d5fe7a921b9d01f26eb1854b8d.zip |
vim-patch:9.0.0020: with some completion reading past end of string (#19922)
Problem: With some completion reading past end of string.
Solution: Check the length of the string.
https://github.com/vim/vim/commit/f12129f1714f7d2301935bb21d896609bdac221c
-rw-r--r-- | src/nvim/insexpand.c | 12 | ||||
-rw-r--r-- | src/nvim/testdir/test_ins_complete.vim | 8 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index d9f0c3419c..5655b31df1 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -1839,10 +1839,18 @@ static bool ins_compl_stop(const int c, const int prev_mode, bool retval) // but only do this, if the Popup is still visible if (c == Ctrl_E) { ins_compl_delete(); + char_u *p = NULL; 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) { + const int compl_len = get_compl_len(); + const int len = (int)STRLEN(p); + if (len > compl_len) { + ins_bytes_len(p + compl_len, (size_t)(len - compl_len)); + } } retval = true; } diff --git a/src/nvim/testdir/test_ins_complete.vim b/src/nvim/testdir/test_ins_complete.vim index 6f5f72e1ed..54d3844100 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -947,4 +947,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 si0s0 + bwipe! +endfunc + + " vim: shiftwidth=2 sts=2 expandtab |