changeset 22822:0b4658e030cb v8.2.1959

patch 8.2.1959: crash when terminal buffer name is made empty Commit: https://github.com/vim/vim/commit/00806bceb6dc9c8dcd308e5f7e50f720f7dc71b0 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Nov 5 19:36:38 2020 +0100 patch 8.2.1959: crash when terminal buffer name is made empty Problem: Crash when terminal buffer name is made empty. (Dhiraj Mishra) Solution: Fall back to "[No Name]". (closes https://github.com/vim/vim/issues/7262)
author Bram Moolenaar <Bram@vim.org>
date Thu, 05 Nov 2020 19:45:04 +0100
parents 3e8f3dc13538
children 1662d391e67e
files src/buffer.c src/proto/buffer.pro src/terminal.c src/testdir/test_terminal.vim src/version.c
diffstat 5 files changed, 30 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -5648,8 +5648,19 @@ buf_spname(buf_T *buf)
     }
 
     if (buf->b_fname == NULL)
+	return buf_get_fname(buf);
+    return NULL;
+}
+
+/*
+ * Get "buf->b_fname", use "[No Name]" if it is NULL.
+ */
+    char_u *
+buf_get_fname(buf_T *buf)
+{
+    if (buf->b_fname == NULL)
 	return (char_u *)_("[No Name]");
-    return NULL;
+    return buf->b_fname;
 }
 
 /*
--- a/src/proto/buffer.pro
+++ b/src/proto/buffer.pro
@@ -66,6 +66,7 @@ int bt_dontwrite(buf_T *buf);
 int bt_dontwrite_msg(buf_T *buf);
 int buf_hide(buf_T *buf);
 char_u *buf_spname(buf_T *buf);
+char_u *buf_get_fname(buf_T *buf);
 void set_buflisted(int on);
 int buf_contents_changed(buf_T *buf);
 void wipe_buffer(buf_T *buf, int aucmd);
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -1598,7 +1598,7 @@ term_try_stop_job(buf_T *buf)
 	char_u	buff[DIALOG_MSG_SIZE];
 	int	ret;
 
-	dialog_msg(buff, _("Kill job in \"%s\"?"), buf->b_fname);
+	dialog_msg(buff, _("Kill job in \"%s\"?"), buf_get_fname(buf));
 	ret = vim_dialog_yesnocancel(VIM_QUESTION, NULL, buff, 1);
 	if (ret == VIM_YES)
 	    how = "kill";
@@ -4517,6 +4517,7 @@ term_get_status_text(term_T *term)
     {
 	char_u *txt;
 	size_t len;
+	char_u *fname;
 
 	if (term->tl_normal_mode)
 	{
@@ -4533,11 +4534,12 @@ term_get_status_text(term_T *term)
 	    txt = (char_u *)_("running");
 	else
 	    txt = (char_u *)_("finished");
-	len = 9 + STRLEN(term->tl_buffer->b_fname) + STRLEN(txt);
+	fname = buf_get_fname(term->tl_buffer);
+	len = 9 + STRLEN(fname) + STRLEN(txt);
 	term->tl_status_text = alloc(len);
 	if (term->tl_status_text != NULL)
 	    vim_snprintf((char *)term->tl_status_text, len, "%s [%s]",
-						term->tl_buffer->b_fname, txt);
+								   fname, txt);
     }
     return term->tl_status_text;
 }
--- a/src/testdir/test_terminal.vim
+++ b/src/testdir/test_terminal.vim
@@ -41,6 +41,16 @@ func Test_terminal_basic()
   unlet g:job
 endfunc
 
+func Test_terminal_no_name()
+  let buf = Run_shell_in_terminal({})
+  call assert_match('^!', bufname(buf))
+  0file
+  call assert_equal("", bufname(buf))
+  call assert_match('\[No Name\]', execute('file'))
+  call StopShellInTerminal(buf)
+  call TermWait(buf)
+endfunc
+
 func Test_terminal_TerminalWinOpen()
   au TerminalWinOpen * let b:done = 'yes'
   let buf = Run_shell_in_terminal({})
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1959,
+/**/
     1958,
 /**/
     1957,