To: vim_dev@googlegroups.com Subject: Patch 8.0.0886 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.0886 Problem: Crash when using ":term ls". Solution: Fix line number computation. Add a test for this. Files: src/terminal.c, src/testdir/test_terminal.vim *** ../vim-8.0.0885/src/terminal.c 2017-08-06 21:36:17.452859481 +0200 --- src/terminal.c 2017-08-07 20:34:29.422170596 +0200 *************** *** 695,708 **** static void add_scrollback_line_to_buffer(term_T *term, char_u *text, int len) { ! linenr_T lnum = term->tl_scrollback.ga_len - 1; ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE); ! if (lnum == 0) { /* Delete the empty line that was in the empty buffer. */ ! curbuf = term->tl_buffer; ! ml_delete(2, FALSE); curbuf = curwin->w_buffer; } } --- 695,710 ---- static void add_scrollback_line_to_buffer(term_T *term, char_u *text, int len) { ! buf_T *buf = term->tl_buffer; ! int empty = (buf->b_ml.ml_flags & ML_EMPTY); ! linenr_T lnum = buf->b_ml.ml_line_count; ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE); ! if (empty) { /* Delete the empty line that was in the empty buffer. */ ! curbuf = buf; ! ml_delete(1, FALSE); curbuf = curwin->w_buffer; } } *** ../vim-8.0.0885/src/testdir/test_terminal.vim 2017-08-06 21:36:17.452859481 +0200 --- src/testdir/test_terminal.vim 2017-08-07 20:36:55.865095396 +0200 *************** *** 210,215 **** --- 210,240 ---- call delete('Xtext') endfunc + func Test_terminal_scroll() + call writefile(range(1, 200), 'Xtext') + if has('win32') + let cmd = 'cmd /c "type Xtext"' + else + let cmd = "cat Xtext" + endif + let buf = term_start(cmd) + + let g:job = term_getjob(buf) + call WaitFor('job_status(g:job) == "dead"') + call term_wait(buf) + if has('win32') + " TODO: this should not be needed + sleep 100m + endif + + call assert_equal('1', getline(1)) + call assert_equal('49', getline(49)) + call assert_equal('200', getline(200)) + + exe buf . 'bwipe' + call delete('Xtext') + endfunc + func Test_terminal_size() let cmd = Get_cat_123_cmd() *** ../vim-8.0.0885/src/version.c 2017-08-06 21:36:17.452859481 +0200 --- src/version.c 2017-08-07 20:10:00.296948489 +0200 *************** *** 771,772 **** --- 771,774 ---- { /* Add new patch number below this line */ + /**/ + 886, /**/ -- An indication you must be a manager: You believe you never have any problems in your life, just "issues" and "improvement opportunities". /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///