Skip to content

Commit f8d57a5

Browse files
committed
patch 8.0.0886: crash when using ":term ls"
Problem: Crash when using ":term ls". Solution: Fix line number computation. Add a test for this.
1 parent 33a43be commit f8d57a5

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

src/terminal.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,14 +695,16 @@ term_job_running(term_T *term)
695695
static void
696696
add_scrollback_line_to_buffer(term_T *term, char_u *text, int len)
697697
{
698-
linenr_T lnum = term->tl_scrollback.ga_len - 1;
698+
buf_T *buf = term->tl_buffer;
699+
int empty = (buf->b_ml.ml_flags & ML_EMPTY);
700+
linenr_T lnum = buf->b_ml.ml_line_count;
699701

700702
ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE);
701-
if (lnum == 0)
703+
if (empty)
702704
{
703705
/* Delete the empty line that was in the empty buffer. */
704-
curbuf = term->tl_buffer;
705-
ml_delete(2, FALSE);
706+
curbuf = buf;
707+
ml_delete(1, FALSE);
706708
curbuf = curwin->w_buffer;
707709
}
708710
}

src/testdir/test_terminal.vim

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,31 @@ func Test_terminal_scrape_multibyte()
210210
call delete('Xtext')
211211
endfunc
212212

213+
func Test_terminal_scroll()
214+
call writefile(range(1, 200), 'Xtext')
215+
if has('win32')
216+
let cmd = 'cmd /c "type Xtext"'
217+
else
218+
let cmd = "cat Xtext"
219+
endif
220+
let buf = term_start(cmd)
221+
222+
let g:job = term_getjob(buf)
223+
call WaitFor('job_status(g:job) == "dead"')
224+
call term_wait(buf)
225+
if has('win32')
226+
" TODO: this should not be needed
227+
sleep 100m
228+
endif
229+
230+
call assert_equal('1', getline(1))
231+
call assert_equal('49', getline(49))
232+
call assert_equal('200', getline(200))
233+
234+
exe buf . 'bwipe'
235+
call delete('Xtext')
236+
endfunc
237+
213238
func Test_terminal_size()
214239
let cmd = Get_cat_123_cmd()
215240

src/version.c

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

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
886,
772774
/**/
773775
885,
774776
/**/

0 commit comments

Comments
 (0)