patch 9.2.0167: terminal: setting buftype=terminal may cause a crash

Problem:  setting buftype=terminal may cause a crash
          (lacygoill, after v9.2.0127)
Solution: Validate that curwin->w_buffer->b_term is not null

fixes:  #19686
closes: #19676

Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Christian Brabandt
2026-03-14 17:31:45 +00:00
parent 84c7a5d18f
commit ba27e4fffa
3 changed files with 9 additions and 2 deletions
+2 -2
View File
@@ -6984,7 +6984,7 @@ var2fpos(
if (name[1] == '0') // "w0": first visible line
{
#ifdef FEAT_TERMINAL
if (bt_terminal(curwin->w_buffer))
if (bt_terminal(curwin->w_buffer) && curwin->w_buffer->b_term != NULL)
may_move_terminal_to_buffer(curwin->w_buffer->b_term, TRUE);
#endif
update_topline();
@@ -6996,7 +6996,7 @@ var2fpos(
else if (name[1] == '$') // "w$": last visible line
{
#ifdef FEAT_TERMINAL
if (bt_terminal(curwin->w_buffer))
if (bt_terminal(curwin->w_buffer) && curwin->w_buffer->b_term != NULL)
may_move_terminal_to_buffer(curwin->w_buffer->b_term, TRUE);
#endif
validate_botline();
+5
View File
@@ -1203,6 +1203,11 @@ func Test_term_getpos()
call assert_true(str2nr(result[0]) > 1)
call StopVimInTerminal(buf)
" this crashed
new
setl buftype=terminal
call assert_equal(2, line('w0') + line('w$'))
bw
endfunc
" vim: shiftwidth=2 sts=2 expandtab
+2
View File
@@ -734,6 +734,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
167,
/**/
166,
/**/