summaryrefslogtreecommitdiff
path: root/src/misc2.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-05-16 19:40:59 +0100
committerBram Moolenaar <Bram@vim.org>2022-05-16 19:40:59 +0100
commit7ce5b2b590256ce53d6af28c1d203fb3bc1d2d97 (patch)
treed40856d0b0eb3723b94a0543db98cd8d96cb2d50 /src/misc2.c
parent60ae0e71490c97f2871a6344aca61cacf220f813 (diff)
downloadvim-git-7ce5b2b590256ce53d6af28c1d203fb3bc1d2d97.tar.gz
patch 8.2.4969: changing text in Visual mode may cause invalid memory accessv8.2.4969
Problem: Changing text in Visual mode may cause invalid memory access. Solution: Check the Visual position after making a change.
Diffstat (limited to 'src/misc2.c')
-rw-r--r--src/misc2.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/misc2.c b/src/misc2.c
index 7840ea98f..e03ca4936 100644
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -622,6 +622,31 @@ 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;
+ }
+ }
+}
+
#if defined(FEAT_TEXTOBJ) || defined(PROTO)
/*
* Make sure curwin->w_cursor is not on the NUL at the end of the line.
@@ -2416,7 +2441,7 @@ get_user_name(char_u *buf, int len)
return OK;
}
-#if defined(EXITFREE) || defined(PROTOS)
+#if defined(EXITFREE) || defined(PROTO)
/*
* Free the memory allocated by get_user_name()
*/