]> granicus.if.org Git - vim/commitdiff
patch 8.2.1959: crash when terminal buffer name is made empty v8.2.1959
authorBram Moolenaar <Bram@vim.org>
Thu, 5 Nov 2020 18:36:38 +0000 (19:36 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 5 Nov 2020 18:36:38 +0000 (19:36 +0100)
Problem:    Crash when terminal buffer name is made empty. (Dhiraj Mishra)
Solution:   Fall back to "[No Name]". (closes #7262)

src/buffer.c
src/proto/buffer.pro
src/terminal.c
src/testdir/test_terminal.vim
src/version.c

index c804348e19c3e5b2b7181d50e7ca2008778aacfb..a4c6a00b531d52d9e63d535229228e36245182ae 100644 (file)
@@ -5648,10 +5648,21 @@ buf_spname(buf_T *buf)
     }
 
     if (buf->b_fname == NULL)
-       return (char_u *)_("[No Name]");
+       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 buf->b_fname;
+}
+
 /*
  * Set 'buflisted' for curbuf to "on" and trigger autocommands if it changed.
  */
index 3fdcc69497cde7fabe69cd150e470a4d052c5442..82bcaf3c1fa7e581ec6ff867912b6a3edc695cf6 100644 (file)
@@ -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);
index 7c784b35df852d38885a416df4b7d964590cdb03..ff3e3bd6a540898eb2da8ee001a69d1ece92d45f 100644 (file)
@@ -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;
 }
index f5b99bcc885a56e766ddf03443b8e4f1a36cecfb..ece8120d58b194ed0ff3235963275d29501c190e 100644 (file)
@@ -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({})
index ef4be7d63989b0b655f02341c1b8c77de272e248..f5d94cc724c9a9dc50dbf7c210af4e764540d2cc 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1959,
 /**/
     1958,
 /**/