aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-04-11 21:29:18 +0800
committerGitHub <noreply@github.com>2022-04-11 21:29:18 +0800
commit356cff78ece597059133e33eceb955f72286a319 (patch)
tree821af4b01506ae26d16a3e272adab4ea1c8d5fa2 /src/nvim/eval.c
parentf0d07dcb7499412f42654690183606d2551b6d66 (diff)
downloadrneovim-356cff78ece597059133e33eceb955f72286a319.tar.gz
rneovim-356cff78ece597059133e33eceb955f72286a319.tar.bz2
rneovim-356cff78ece597059133e33eceb955f72286a319.zip
vim-patch:8.2.4734: getcharpos() may change a mark position (#18077)
Problem: getcharpos() may change a mark position. Solution: Copy the mark position. (closes vim/vim#10148) https://github.com/vim/vim/commit/3caf1cce2b85a8f24195d057f0ad63082543e99e
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index c1905b31d0..3e855ece15 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -7739,7 +7739,6 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
static pos_T pos;
- pos_T *pp;
// Argument can be [lnum, col, coladd].
if (tv->v_type == VAR_LIST) {
@@ -7799,33 +7798,31 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret
if (name == NULL) {
return NULL;
}
- if (name[0] == '.') { // Cursor.
+
+ pos.lnum = 0;
+ if (name[0] == '.') {
+ // cursor
pos = curwin->w_cursor;
- if (charcol) {
- pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col);
- }
- return &pos;
- }
- if (name[0] == 'v' && name[1] == NUL) { // Visual start.
+ } else if (name[0] == 'v' && name[1] == NUL) {
+ // Visual start
if (VIsual_active) {
pos = VIsual;
} else {
pos = curwin->w_cursor;
}
- if (charcol) {
- pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col);
- }
- return &pos;
- }
- if (name[0] == '\'') { // Mark.
- pp = getmark_buf_fnum(curbuf, (uint8_t)name[1], false, ret_fnum);
+ } else if (name[0] == '\'') {
+ // mark
+ const pos_T *const pp = getmark_buf_fnum(curbuf, (uint8_t)name[1], false, ret_fnum);
if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0) {
return NULL;
}
+ pos = *pp;
+ }
+ if (pos.lnum != 0) {
if (charcol) {
- pp->col = buf_byteidx_to_charidx(curbuf, pp->lnum, pp->col);
+ pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col);
}
- return pp;
+ return &pos;
}
pos.coladd = 0;