To: vim_dev@googlegroups.com Subject: Patch 7.4.2347 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.2347 Problem: Crash when closing a buffer while Visual mode is active. (Dominique Pelle) Solution: Adjust the position before computing the number of lines. When closing the current buffer stop Visual mode. Files: src/buffer.c, src/normal.c, src/testdir/test_normal.vim *** ../vim-7.4.2346/src/buffer.c 2016-09-04 23:41:36.973433429 +0200 --- src/buffer.c 2016-09-08 23:31:18.260925052 +0200 *************** *** 578,583 **** --- 578,588 ---- if (buf->b_ffname == NULL) del_buf = TRUE; + /* When closing the current buffer stop Visual mode before freeing + * anything. */ + if (buf == curbuf) + end_visual_mode(); + /* * Free all things allocated for this buffer. * Also calls the "BufDelete" autocommands when del_buf is TRUE. *************** *** 1379,1384 **** --- 1384,1393 ---- } } + /* When closing the current buffer stop Visual mode. */ + if (buf == curbuf) + end_visual_mode(); + /* * If deleting the last (listed) buffer, make it empty. * The last (listed) buffer cannot be unloaded. *** ../vim-7.4.2346/src/normal.c 2016-09-04 20:34:55.763537404 +0200 --- src/normal.c 2016-09-08 23:35:06.131082221 +0200 *************** *** 1609,1614 **** --- 1609,1616 ---- oap->start = curwin->w_cursor; } + /* Just in case lines were deleted that make the position invalid. */ + check_pos(curwin->w_buffer, &oap->end); oap->line_count = oap->end.lnum - oap->start.lnum + 1; #ifdef FEAT_VIRTUALEDIT *************** *** 9451,9460 **** #ifdef FEAT_MBYTE /* prevent from moving onto a trail byte */ if (has_mbyte) - { - check_pos(curwin->w_buffer, &oap->end); mb_adjustpos(curwin->w_buffer, &oap->end); - } #endif getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol); --- 9453,9459 ---- *** ../vim-7.4.2346/src/testdir/test_normal.vim 2016-09-06 20:37:38.206149358 +0200 --- src/testdir/test_normal.vim 2016-09-08 23:23:15.304888249 +0200 *************** *** 1998,2000 **** --- 1998,2014 ---- " clean up bw! endfu + + func! Test_normal47_visual_buf_wipe() + " This was causing a crash or ml_get error. + enew! + call setline(1,'xxx') + normal $ + new + call setline(1, range(1,2)) + 2 + exe "norm \$" + bw! + norm yp + set nomodified + endfu *** ../vim-7.4.2346/src/version.c 2016-09-08 22:10:04.753618339 +0200 --- src/version.c 2016-09-08 23:34:18.543465683 +0200 *************** *** 765,766 **** --- 765,768 ---- { /* Add new patch number below this line */ + /**/ + 2347, /**/ -- hundred-and-one symptoms of being an internet addict: 205. You're constantly yelling at your spouse, family, roommate, whatever, for using the phone for stupid things...like talking. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///