diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-03-27 09:37:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-27 09:37:04 +0800 |
commit | bad218cd6413dd60a1ed9907f882fbf2e92515f1 (patch) | |
tree | 55dcee9dc9fe4b38d313e18649181b0af2253da7 | |
parent | 2257ade3dc2daab5ee12d27807c0b3bcf103cd29 (diff) | |
download | rneovim-bad218cd6413dd60a1ed9907f882fbf2e92515f1.tar.gz rneovim-bad218cd6413dd60a1ed9907f882fbf2e92515f1.tar.bz2 rneovim-bad218cd6413dd60a1ed9907f882fbf2e92515f1.zip |
vim-patch:9.0.1429: invalid memory access when ending insert mode (#22792)
Problem: Invalid memory access when ending insert mode.
Solution: Check if the insert_skip value is valid.
https://github.com/vim/vim/commit/1a08a3e2a584889f19b84a27672134649b73da58
Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r-- | src/nvim/edit.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 0983d025e5..26101d06ed 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2294,11 +2294,11 @@ static void stop_insert(pos_T *end_insert_pos, int esc, int nomove) // Don't do it when "restart_edit" was set and nothing was inserted, // otherwise CTRL-O w and then <Left> will clear "last_insert". ptr = get_inserted(); - if (did_restart_edit == 0 || (ptr != NULL - && (int)strlen(ptr) > new_insert_skip)) { + int added = ptr == NULL ? 0 : (int)strlen(ptr) - new_insert_skip; + if (did_restart_edit == 0 || added > 0) { xfree(last_insert); last_insert = ptr; - last_insert_skip = new_insert_skip; + last_insert_skip = added < 0 ? 0 : new_insert_skip; } else { xfree(ptr); } |