diff options
author | Bram Moolenaar <Bram@vim.org> | 2016-09-04 20:35:01 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2016-09-04 20:35:01 +0200 |
commit | d5824ce1b5491df7d2eb0b66189d366fa67b4585 (patch) | |
tree | c714124ce2cbbb424824917b9058da7cdf82cb9c /src/misc2.c | |
parent | 30180b8dad5c1478e7920e56a71352cb318fadb0 (diff) | |
download | vim-git-d5824ce1b5491df7d2eb0b66189d366fa67b4585.tar.gz |
patch 7.4.2326v7.4.2326
Problem: Illegal memory access when Visual selection starts in invalid
position. (Dominique Pelle)
Solution: Correct position when needed.
Diffstat (limited to 'src/misc2.c')
-rw-r--r-- | src/misc2.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/misc2.c b/src/misc2.c index 7c639d6bb..4d914d233 100644 --- 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 |