]> granicus.if.org Git - vim/commitdiff
patch 7.4.2326 v7.4.2326
authorBram Moolenaar <Bram@vim.org>
Sun, 4 Sep 2016 18:35:01 +0000 (20:35 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 4 Sep 2016 18:35:01 +0000 (20:35 +0200)
Problem:    Illegal memory access when Visual selection starts in invalid
            position. (Dominique Pelle)
Solution:   Correct position when needed.

src/misc2.c
src/normal.c
src/proto/misc2.pro
src/version.c

index 7c639d6bbf6a5b69e6c0edd13c992e59e83ca564..4d914d233e64618ba2cdecae98e245916f37fe67 100644 (file)
@@ -504,6 +504,28 @@ get_cursor_rel_lnum(
     return retval;
 }
 
+/*
+ * 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.
  */
index 0f9b23051da48f89bafd30bb3b3c03777590c99f..edaa740e4cfcd06ed3acd128c61046071f9669d6 100644 (file)
@@ -9451,7 +9451,10 @@ get_op_vcol(
 #ifdef FEAT_MBYTE
     /* prevent from moving onto a trail byte */
     if (has_mbyte)
+    {
+       check_pos(curwin->w_buffer, &oap->end);
        mb_adjustpos(curwin->w_buffer, &oap->end);
+    }
 #endif
 
     getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol);
index 70c7dae5b6bb259dfae24cab905ff3ff9736da46..d18ae2033068e7c972da34fb6334aab280e7a3e6 100644 (file)
@@ -12,6 +12,7 @@ int dec_cursor(void);
 int dec(pos_T *lp);
 int decl(pos_T *lp);
 linenr_T get_cursor_rel_lnum(win_T *wp, linenr_T lnum);
+void check_pos(buf_T *buf, pos_T *pos);
 void check_cursor_lnum(void);
 void check_cursor_col(void);
 void check_cursor_col_win(win_T *win);
index 95777312dc4f2a7cc1060f1fba545f3572ef5969..06fb3ef5527410c869479c9f7ba1c90d1ba91f84 100644 (file)
@@ -763,6 +763,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2326,
 /**/
     2325,
 /**/