diff options
author | raichoo <raichoo@googlemail.com> | 2017-03-11 11:33:15 +0100 |
---|---|---|
committer | raichoo <raichoo@googlemail.com> | 2017-03-19 21:14:11 +0100 |
commit | e888864c28033546b827c07d9dd095348fff23bd (patch) | |
tree | b47475f3930fb1f3a627105a02536e7b947cf8cc /src/nvim/cursor.c | |
parent | 42caeccce6e50fa3b8b25fe3076ac2fbd555b152 (diff) | |
download | rneovim-e888864c28033546b827c07d9dd095348fff23bd.tar.gz rneovim-e888864c28033546b827c07d9dd095348fff23bd.tar.bz2 rneovim-e888864c28033546b827c07d9dd095348fff23bd.zip |
vim-patch:7.4.2326
Problem: Illegal memory access when Visual selection starts in invalid
position. (Dominique Pelle)
Solution: Correct position when needed.
https://github.com/vim/vim/commit/d5824ce1b5491df7d2eb0b66189d366fa67b4585
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 3ba9da34f2..01476627de 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -294,6 +294,24 @@ linenr_T get_cursor_rel_lnum(win_T *wp, linenr_T lnum) return (lnum < cursor) ? -retval : 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. */ |