diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-07-06 14:40:04 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-07-06 20:01:01 +0800 |
commit | 1a490a5bc552fcdc299684b725c5044a9e9c73c7 (patch) | |
tree | eb972208a75d0a28213cc040bad4d093ab2aec89 /src | |
parent | 8e03d42ec885cf846b40e843ceb6fd42fc9f4029 (diff) | |
download | rneovim-1a490a5bc552fcdc299684b725c5044a9e9c73c7.tar.gz rneovim-1a490a5bc552fcdc299684b725c5044a9e9c73c7.tar.bz2 rneovim-1a490a5bc552fcdc299684b725c5044a9e9c73c7.zip |
fix(normal): fix segfault with bracket command jumping to a mark
vim-patch:9.0.0043: insufficient testing for bracket commands
Problem: Insufficient testing for bracket commands.
Solution: Add a few more tests. (closes vim/vim#10668)
https://github.com/vim/vim/commit/cf34434b5e840dda4a21cd9c0bee24e3e43a674d
Cherry-pick a change from patch 8.2.0369.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/normal.c | 18 | ||||
-rw-r--r-- | src/nvim/testdir/test_normal.vim | 41 |
2 files changed, 46 insertions, 13 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c index c12b807be9..3a552ef053 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -5011,8 +5011,6 @@ static void nv_bracket_block(cmdarg_T *cap, const pos_T *old_pos) /// cap->arg is BACKWARD for "[" and FORWARD for "]". static void nv_brackets(cmdarg_T *cap) { - pos_T prev_pos; - pos_T *pos = NULL; // init for GCC pos_T old_pos; // cursor position before command int flag; long n; @@ -5091,19 +5089,19 @@ static void nv_brackets(cmdarg_T *cap) nv_put_opt(cap, true); } else if (cap->nchar == '\'' || cap->nchar == '`') { // "['", "[`", "]'" and "]`": jump to next mark - fmark_T *fm = NULL; - pos = &curwin->w_cursor; + fmark_T *fm = pos_to_mark(curbuf, NULL, curwin->w_cursor); + fmark_T *prev_fm; for (n = cap->count1; n > 0; n--) { - prev_pos = *pos; - fm = getnextmark(pos, cap->cmdchar == '[' ? BACKWARD : FORWARD, + prev_fm = fm; + fm = getnextmark(&fm->mark, cap->cmdchar == '[' ? BACKWARD : FORWARD, cap->nchar == '\''); - if (pos == NULL) { + if (fm == NULL) { break; - } else { - pos = fm != NULL ? &fm->mark : NULL; // Adjust for the next iteration. } } - fm = fm == NULL ? pos_to_mark(curbuf, NULL, curwin->w_cursor) : fm; + if (fm == NULL) { + fm = prev_fm; + } MarkMove flags = kMarkContext; flags |= cap->nchar == '\'' ? kMarkBeginLine: 0; nv_mark_move_to(cap, flags, fm); diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 82ba2cfd48..f146726b7b 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -1422,9 +1422,16 @@ func Test_normal27_bracket() call assert_equal(5, line('.')) call assert_equal(3, col('.')) - " No mark after line 21, cursor moves to first non blank on current line + " No mark before line 1, cursor moves to first non-blank on current line + 1 + norm! 5|[' + call assert_equal(' 1 b', getline('.')) + call assert_equal(1, line('.')) + call assert_equal(3, col('.')) + + " No mark after line 21, cursor moves to first non-blank on current line 21 - norm! $]' + norm! 5|]' call assert_equal(' 21 b', getline('.')) call assert_equal(21, line('.')) call assert_equal(3, col('.')) @@ -1441,12 +1448,40 @@ func Test_normal27_bracket() call assert_equal(20, line('.')) call assert_equal(8, col('.')) + " No mark before line 1, cursor does not move + 1 + norm! 5|[` + call assert_equal(' 1 b', getline('.')) + call assert_equal(1, line('.')) + call assert_equal(5, col('.')) + + " No mark after line 21, cursor does not move + 21 + norm! 5|]` + call assert_equal(' 21 b', getline('.')) + call assert_equal(21, line('.')) + call assert_equal(5, col('.')) + + " Count too large for [` + " cursor moves to first lowercase mark + norm! 99[` + call assert_equal(' 1 b', getline('.')) + call assert_equal(1, line('.')) + call assert_equal(7, col('.')) + + " Count too large for ]` + " cursor moves to last lowercase mark + norm! 99]` + call assert_equal(' 20 b', getline('.')) + call assert_equal(20, line('.')) + call assert_equal(8, col('.')) + " clean up bw! endfunc +" Test for ( and ) sentence movements func Test_normal28_parenthesis() - " basic testing for ( and ) new call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) |