# HG changeset patch # User Christian Brabandt # Date 1534798806 -7200 # Node ID 23d6d9e9ae3e9c501ba5de315362701a375677e3 # Parent 4e22895e5442de13effbc01483f422e65ec448a4 patch 8.1.0303: line2byte() is wrong for last line with 'noeol' commit https://github.com/vim/vim/commit/c26f7c60532a37a2bf0a5e69aa81081b440dfc38 Author: Bram Moolenaar Date: Mon Aug 20 22:53:04 2018 +0200 patch 8.1.0303: line2byte() is wrong for last line with 'noeol' Problem: line2byte() is wrong for last line with 'noeol' and 'nofixeol'. Solution: Fix off-by-one error. (Shane Harper, closes https://github.com/vim/vim/issues/3351) diff --git a/src/memline.c b/src/memline.c --- a/src/memline.c +++ b/src/memline.c @@ -5267,7 +5267,7 @@ ml_find_line_or_offset(buf_T *buf, linen /* Don't count the last line break if 'noeol' and ('bin' or * 'nofixeol'). */ if ((!buf->b_p_fixeol || buf->b_p_bin) && !buf->b_p_eol - && buf->b_ml.ml_line_count == lnum) + && lnum > buf->b_ml.ml_line_count) size -= ffdos + 1; } diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim --- a/src/testdir/test_functions.vim +++ b/src/testdir/test_functions.vim @@ -682,6 +682,7 @@ endfunc func Test_byte2line_line2byte() new + set endofline call setline(1, ['a', 'bc', 'd']) set fileformat=unix @@ -702,7 +703,16 @@ func Test_byte2line_line2byte() call assert_equal([-1, -1, 1, 4, 8, 11, -1], \ map(range(-1, 5), 'line2byte(v:val)')) - set fileformat& + bw! + set noendofline nofixendofline + normal a- + for ff in ["unix", "mac", "dos"] + let &fileformat = ff + call assert_equal(1, line2byte(1)) + call assert_equal(2, line2byte(2)) " line2byte(line("$") + 1) is the buffer size plus one (as per :help line2byte). + endfor + + set endofline& fixendofline& fileformat& bw! endfunc diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -795,6 +795,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 303, +/**/ 302, /**/ 301,