diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-05-17 08:47:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-17 08:47:45 +0800 |
commit | 6613f58cebde7db4e69709b84d511c32a7c4ce32 (patch) | |
tree | 55b36c6b2f52b6f192fdbe36d47bb0469473bede /src/nvim/cursor.c | |
parent | 07ade91f217a0ed307ca87b4391d803ec0ab61cb (diff) | |
parent | 527e861cbb9c47411c4ba86dbdb9fc79bde47452 (diff) | |
download | rneovim-6613f58cebde7db4e69709b84d511c32a7c4ce32.tar.gz rneovim-6613f58cebde7db4e69709b84d511c32a7c4ce32.tar.bz2 rneovim-6613f58cebde7db4e69709b84d511c32a7c4ce32.zip |
Merge pull request #18598 from zeertzjq/vim-8.2.4968
vim-patch:8.2.{4121,4968,4969}: invalid memory access
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) |