diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2017-11-13 08:30:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-13 08:30:25 +0100 |
commit | 8fff2ef74aae47042c4ee903ae996aa789787fe1 (patch) | |
tree | e23eee0161664ccba459f366503d27d1e94ce2f0 | |
parent | 8d8212d384f668e4e6dfea64e169ec85daef44a2 (diff) | |
download | rneovim-8fff2ef74aae47042c4ee903ae996aa789787fe1.tar.gz rneovim-8fff2ef74aae47042c4ee903ae996aa789787fe1.tar.bz2 rneovim-8fff2ef74aae47042c4ee903ae996aa789787fe1.zip |
vim-patch:8.0.0227 (#7548)
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.
https://github.com/vim/vim/commit/2aa5f696b91a51f29873e340de4bdc182e1e8dd4
-rw-r--r-- | src/nvim/fileio.c | 3 | ||||
-rw-r--r-- | src/nvim/testdir/test_fileformat.vim | 2 |
2 files changed, 3 insertions, 2 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index a7676e88f0..ae6c3f96e3 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -1622,7 +1622,8 @@ rewind_retry: *ptr = NUL; /* end of line */ len = (colnr_T)(ptr - line_start + 1); if (fileformat == EOL_DOS) { - if (ptr[-1] == CAR) { /* remove CR */ + if (ptr > line_start && ptr[-1] == CAR) { + // remove CR before NL ptr[-1] = NUL; len--; } else if (ff_error != EOL_DOS) { diff --git a/src/nvim/testdir/test_fileformat.vim b/src/nvim/testdir/test_fileformat.vim index de505d3bd0..8dc25f62b1 100644 --- a/src/nvim/testdir/test_fileformat.vim +++ b/src/nvim/testdir/test_fileformat.vim @@ -17,7 +17,7 @@ func Test_fileformat_after_bw() endfunc func Test_fileformat_autocommand() - let filecnt = ["\<CR>", "foobar\<CR>", "eins\<CR>", "\<CR>", "zwei\<CR>", "drei", "vier", "fünf", ""] + let filecnt = ["", "foobar\<CR>", "eins\<CR>", "\<CR>", "zwei\<CR>", "drei", "vier", "fünf", ""] let ffs = &ffs call writefile(filecnt, 'Xfile', 'b') au BufReadPre Xfile set ffs=dos ff=dos |