diff src/misc2.c @ 10110:cfb38b57d407 v7.4.2326

commit https://github.com/vim/vim/commit/d5824ce1b5491df7d2eb0b66189d366fa67b4585 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Sep 4 20:35:01 2016 +0200 patch 7.4.2326 Problem: Illegal memory access when Visual selection starts in invalid position. (Dominique Pelle) Solution: Correct position when needed.
author Christian Brabandt <cb@256bit.org>
date Sun, 04 Sep 2016 20:45:05 +0200
parents 4aead6a9b7a9
children c036c0f636d5
line wrap: on
line diff
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -505,6 +505,28 @@ get_cursor_rel_lnum(
 }
 
 /*
+ * Make sure "pos.lnum" and "pos.col" are valid in "buf".
+ * This allows for the col to be on the NUL byte.
+ */
+    void
+check_pos(buf_T *buf, pos_T *pos)
+{
+    char_u *line;
+    colnr_T len;
+
+    if (pos->lnum > buf->b_ml.ml_line_count)
+	pos->lnum = buf->b_ml.ml_line_count;
+
+    if (pos->col > 0)
+    {
+	line = ml_get_buf(buf, pos->lnum, FALSE);
+	len = (colnr_T)STRLEN(line);
+	if (pos->col > len)
+	    pos->col = len;
+    }
+}
+
+/*
  * Make sure curwin->w_cursor.lnum is valid.
  */
     void