summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-08-07 20:38:42 +0200
committerBram Moolenaar <Bram@vim.org>2017-08-07 20:38:42 +0200
commitf8d57a50496d854f3e82725bfde1543c9d01ff98 (patch)
treee2f112a775b388c4f20a2680cece5de45d6cff6a
parent33a43bee9cdc62f9cd0999eb23c6eca01b4d2d67 (diff)
patch 8.0.0886: crash when using ":term ls"v8.0.0886
Problem: Crash when using ":term ls". Solution: Fix line number computation. Add a test for this.
-rw-r--r--src/terminal.c10
-rw-r--r--src/testdir/test_terminal.vim25
-rw-r--r--src/version.c2
3 files changed, 33 insertions, 4 deletions
diff --git a/src/terminal.c b/src/terminal.c
index 99b82b2f51..901bb9bed1 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -695,14 +695,16 @@ term_job_running(term_T *term)
static void
add_scrollback_line_to_buffer(term_T *term, char_u *text, int len)
{
- linenr_T lnum = term->tl_scrollback.ga_len - 1;
+ 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 (lnum == 0)
+ if (empty)
{
/* Delete the empty line that was in the empty buffer. */
- curbuf = term->tl_buffer;
- ml_delete(2, FALSE);
+ curbuf = buf;
+ ml_delete(1, FALSE);
curbuf = curwin->w_buffer;
}
}
diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim
index 845f06b6ec..2220a164a4 100644
--- a/src/testdir/test_terminal.vim
+++ b/src/testdir/test_terminal.vim
@@ -210,6 +210,31 @@ func Test_terminal_scrape_multibyte()
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()
diff --git a/src/version.c b/src/version.c
index 2b769ea4f5..4e78e31a2e 100644
--- a/src/version.c
+++ b/src/version.c
@@ -770,6 +770,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 886,
+/**/
885,
/**/
884,