To: vim_dev@googlegroups.com Subject: Patch 8.2.4956 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4956 Problem: Reading past end of line with "gf" in Visual block mode. Solution: Do not include the NUL in the length. Files: src/normal.c, src/testdir/test_gf.vim *** ../vim-8.2.4955/src/normal.c 2022-05-09 20:09:19.290641428 +0100 --- src/normal.c 2022-05-14 21:27:10.729808031 +0100 *************** *** 3671,3679 **** } if (**pp == NUL) *lenp = 0; ! if (has_mbyte && *lenp > 0) ! // Correct the length to include all bytes of the last character. ! *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1; } reset_VIsual_and_resel(); return OK; --- 3671,3686 ---- } if (**pp == NUL) *lenp = 0; ! if (*lenp > 0) ! { ! if (has_mbyte) ! // Correct the length to include all bytes of the last ! // character. ! *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1; ! else if ((*pp)[*lenp - 1] == NUL) ! // Do not include a trailing NUL. ! *lenp -= 1; ! } } reset_VIsual_and_resel(); return OK; *** ../vim-8.2.4955/src/testdir/test_gf.vim 2022-01-31 14:59:33.526943578 +0000 --- src/testdir/test_gf.vim 2022-05-14 21:25:03.329899241 +0100 *************** *** 138,143 **** --- 138,158 ---- call assert_equal('Xtest_gf_visual', bufname('%')) call assert_equal(3, getcurpos()[1]) + " do not include the NUL at the end + call writefile(['x'], 'X') + let save_enc = &enc + for enc in ['latin1', 'utf-8'] + exe "set enc=" .. enc + new + call setline(1, 'X') + set nomodified + exe "normal \$gf" + call assert_equal('X', bufname()) + bwipe! + endfor + let &enc = save_enc + call delete('X') + " line number in visual area is used for file name if has('unix') bwipe! *** ../vim-8.2.4955/src/version.c 2022-05-14 18:47:58.807259718 +0100 --- src/version.c 2022-05-14 21:19:04.510162230 +0100 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 4956, /**/ -- hundred-and-one symptoms of being an internet addict: 200. You really believe in the concept of a "paperless" office. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///