mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
vim-patch:9.0.0530: using freed memory when autocmd changes mark (#21396)
Problem: Using freed memory when autocmd changes mark.
Solution: Copy the mark before editing another buffer.
8ecfa2c56b
Nvim already copies the mark.
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -551,6 +551,7 @@ MarkMoveRes mark_move_to(fmark_T *fm, MarkMove flags)
|
|||||||
// Need to change buffer
|
// Need to change buffer
|
||||||
fm_copy = *fm; // Copy, autocommand may change it
|
fm_copy = *fm; // Copy, autocommand may change it
|
||||||
fm = &fm_copy;
|
fm = &fm_copy;
|
||||||
|
// Jump to the file with the mark
|
||||||
res |= switch_to_mark_buf(fm, !(flags & kMarkJumpList));
|
res |= switch_to_mark_buf(fm, !(flags & kMarkJumpList));
|
||||||
// Failed switching buffer
|
// Failed switching buffer
|
||||||
if (res & kMarkMoveFailed) {
|
if (res & kMarkMoveFailed) {
|
||||||
@@ -568,6 +569,7 @@ MarkMoveRes mark_move_to(fmark_T *fm, MarkMove flags)
|
|||||||
// Move the cursor while keeping track of what changed for the caller
|
// Move the cursor while keeping track of what changed for the caller
|
||||||
pos_T prev_pos = curwin->w_cursor;
|
pos_T prev_pos = curwin->w_cursor;
|
||||||
pos_T pos = fm->mark;
|
pos_T pos = fm->mark;
|
||||||
|
// Set lnum again, autocommands my have changed it
|
||||||
curwin->w_cursor = fm->mark;
|
curwin->w_cursor = fm->mark;
|
||||||
if (flags & kMarkBeginLine) {
|
if (flags & kMarkBeginLine) {
|
||||||
beginline(BL_WHITE | BL_FIX);
|
beginline(BL_WHITE | BL_FIX);
|
||||||
|
@@ -304,4 +304,17 @@ func Test_getmarklist()
|
|||||||
close!
|
close!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" This was using freed memory
|
||||||
|
func Test_jump_mark_autocmd()
|
||||||
|
next 00
|
||||||
|
edit 0
|
||||||
|
sargument
|
||||||
|
au BufEnter 0 all
|
||||||
|
sil norm
|
||||||
|
|
||||||
|
au! BufEnter
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Reference in New Issue
Block a user