Skip to content

Commit 2aa5f69

Browse files
committed
patch 8.0.0227: crash with ff=dos when first line in file has no CR
Problem: Crash when 'fileformat' is forced to "dos" and the first line in the file is empty and does not have a CR character. Solution: Don't check for CR before the start of the buffer.
1 parent 1695f99 commit 2aa5f69

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/fileio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2251,8 +2251,9 @@ readfile(
22512251
len = (colnr_T)(ptr - line_start + 1);
22522252
if (fileformat == EOL_DOS)
22532253
{
2254-
if (ptr[-1] == CAR) /* remove CR */
2254+
if (ptr > line_start && ptr[-1] == CAR)
22552255
{
2256+
/* remove CR before NL */
22562257
ptr[-1] = NUL;
22572258
--len;
22582259
}

src/testdir/test_fileformat.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func Test_fileformat_after_bw()
1717
endfunc
1818

1919
func Test_fileformat_autocommand()
20-
let filecnt = ["\<CR>", "foobar\<CR>", "eins\<CR>", "\<CR>", "zwei\<CR>", "drei", "vier", "fünf", ""]
20+
let filecnt = ["", "foobar\<CR>", "eins\<CR>", "\<CR>", "zwei\<CR>", "drei", "vier", "fünf", ""]
2121
let ffs = &ffs
2222
call writefile(filecnt, 'Xfile', 'b')
2323
au BufReadPre Xfile set ffs=dos ff=dos

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
227,
767769
/**/
768770
226,
769771
/**/

0 commit comments

Comments
 (0)