]> granicus.if.org Git - vim/commitdiff
patch 8.2.1979: "term_opencmd" option of term_start() is truncated v8.2.1979
authorBram Moolenaar <Bram@vim.org>
Thu, 12 Nov 2020 14:12:15 +0000 (15:12 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 12 Nov 2020 14:12:15 +0000 (15:12 +0100)
Problem:    "term_opencmd" option of term_start() is truncated. (Sergey
            Vlasov)
Solution:   Allocate the buffer to hold the command. (closes #7284)

src/terminal.c
src/testdir/test_terminal.vim
src/version.c

index 0fb9f485a616d5095f41a7e308ffa8784e60c805..4e2ff14dda6fe91e1f29e739e345aedb8cd85099 100644 (file)
@@ -3450,15 +3450,19 @@ term_after_channel_closed(term_T *term)
        if (term->tl_finish == TL_FINISH_OPEN
                                   && term->tl_buffer->b_nwindows == 0)
        {
-           char buf[50];
-
-           // TODO: use term_opencmd
-           ch_log(NULL, "terminal job finished, opening window");
-           vim_snprintf(buf, sizeof(buf),
-                   term->tl_opencmd == NULL
-                           ? "botright sbuf %d"
-                           : (char *)term->tl_opencmd, fnum);
-           do_cmdline_cmd((char_u *)buf);
+           char    *cmd = term->tl_opencmd == NULL
+                               ? "botright sbuf %d"
+                               : (char *)term->tl_opencmd;
+           size_t  len = strlen(cmd) + 50;
+           char    *buf = alloc(len);
+
+           if (buf != NULL)
+           {
+               ch_log(NULL, "terminal job finished, opening window");
+               vim_snprintf(buf, len, cmd, fnum);
+               do_cmdline_cmd((char_u *)buf);
+               vim_free(buf);
+           }
        }
        else
            ch_log(NULL, "terminal job finished");
index ece8120d58b194ed0ff3235963275d29501c190e..16ad720f7eafd78caecdf8fc720f808b23c5dff3 100644 (file)
@@ -567,10 +567,12 @@ func Test_terminal_finish_open_close()
   call assert_fails("call term_start(cmd, {'term_opencmd': 'split %d and %s'})", 'E475:')
   call assert_fails("call term_start(cmd, {'term_opencmd': 'split % and %d'})", 'E475:')
 
-  call term_start(cmd, {'term_finish': 'open', 'term_opencmd': '4split | buffer %d'})
+  call term_start(cmd, {'term_finish': 'open', 'term_opencmd': '4split | buffer %d | let g:result = "opened the buffer in a window"'})
   close!
   call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime)
   call assert_equal(4, winheight(0))
+  call assert_equal('opened the buffer in a window', g:result)
+  unlet g:result
   bwipe
 endfunc
 
index caf4db89ae2f29d7bbc941cad53ca4fa7cd6f57c..bb33bcbc096dd002438764b881fe4462d8b07a72 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1979,
 /**/
     1978,
 /**/