diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-05-17 08:10:34 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-05-17 08:16:37 +0800 |
commit | 527e861cbb9c47411c4ba86dbdb9fc79bde47452 (patch) | |
tree | 55b36c6b2f52b6f192fdbe36d47bb0469473bede /src/nvim/cursor.c | |
parent | 26c906f54dafb37f7bc63e136a7a9373d1053fe1 (diff) | |
download | rneovim-527e861cbb9c47411c4ba86dbdb9fc79bde47452.tar.gz rneovim-527e861cbb9c47411c4ba86dbdb9fc79bde47452.tar.bz2 rneovim-527e861cbb9c47411c4ba86dbdb9fc79bde47452.zip |
vim-patch:8.2.4969: changing text in Visual mode may cause invalid memory access
Problem: Changing text in Visual mode may cause invalid memory access.
Solution: Check the Visual position after making a change.
https://github.com/vim/vim/commit/7ce5b2b590256ce53d6af28c1d203fb3bc1d2d97
Diffstat (limited to 'src/nvim/cursor.c')
-rw-r--r-- | src/nvim/cursor.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 11c734479c..1446257f7e 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -399,6 +399,24 @@ void check_cursor(void) check_cursor_col(); } +/// Check if VIsual position is valid, correct it if not. +/// Can be called when in Visual mode and a change has been made. +void check_visual_pos(void) +{ + if (VIsual.lnum > curbuf->b_ml.ml_line_count) { + VIsual.lnum = curbuf->b_ml.ml_line_count; + VIsual.col = 0; + VIsual.coladd = 0; + } else { + int len = (int)STRLEN(ml_get(VIsual.lnum)); + + if (VIsual.col > len) { + VIsual.col = len; + VIsual.coladd = 0; + } + } +} + /// Make sure curwin->w_cursor is not on the NUL at the end of the line. /// Allow it when in Visual mode and 'selection' is not "old". void adjust_cursor_col(void) |