]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.1.0303: line2byte() is wrong for last line with 'noeol' v8.1.0303
authorBram Moolenaar <Bram@vim.org>
Mon, 20 Aug 2018 20:53:04 +0000 (22:53 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 20 Aug 2018 20:53:04 +0000 (22:53 +0200)
Problem:    line2byte() is wrong for last line with 'noeol' and 'nofixeol'.
Solution:   Fix off-by-one error. (Shane Harper, closes #3351)

src/memline.c
src/testdir/test_functions.vim
src/version.c

index a2f0b4f6269b7242707fb988914bde4382a2286a..fb262acef55e328c9b5b066003e05c4379e485e6 100644 (file)
@@ -5267,7 +5267,7 @@ ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp)
        /* 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;
     }
 
index 13db0041e7036ef9f8b25b55c1f9aa93b769900e..848e7986c30607f6ad9323532e43939835c1a99a 100644 (file)
@@ -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
 
index 42a81ccfa8e1091f4797738f657250cef0af9163..d382ff316d3c93bd5c93a4ac5b78f1e00cb064ff 100644 (file)
@@ -794,6 +794,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    303,
 /**/
     302,
 /**/