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:
zeertzjq 2022-12-13 10:47:39 +08:00 committed by GitHub
parent 0b20762c60
commit a6b05cb75d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -551,6 +551,7 @@ MarkMoveRes mark_move_to(fmark_T *fm, MarkMove flags)
// Need to change buffer
fm_copy = *fm; // Copy, autocommand may change it
fm = &fm_copy;
// Jump to the file with the mark
res |= switch_to_mark_buf(fm, !(flags & kMarkJumpList));
// Failed switching buffer
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
pos_T prev_pos = curwin->w_cursor;
pos_T pos = fm->mark;
// Set lnum again, autocommands my have changed it
curwin->w_cursor = fm->mark;
if (flags & kMarkBeginLine) {
beginline(BL_WHITE | BL_FIX);

View File

@ -304,4 +304,17 @@ func Test_getmarklist()
close!
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