Skip to content

Commit 47c5ea4

Browse files
committed
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Problem: "term_opencmd" option of term_start() is truncated. (Sergey Vlasov) Solution: Allocate the buffer to hold the command. (closes #7284)
1 parent 957cf67 commit 47c5ea4

3 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/terminal.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3450,15 +3450,19 @@ term_after_channel_closed(term_T *term)
34503450
if (term->tl_finish == TL_FINISH_OPEN
34513451
&& term->tl_buffer->b_nwindows == 0)
34523452
{
3453-
char buf[50];
3454-
3455-
// TODO: use term_opencmd
3456-
ch_log(NULL, "terminal job finished, opening window");
3457-
vim_snprintf(buf, sizeof(buf),
3458-
term->tl_opencmd == NULL
3459-
? "botright sbuf %d"
3460-
: (char *)term->tl_opencmd, fnum);
3461-
do_cmdline_cmd((char_u *)buf);
3453+
char *cmd = term->tl_opencmd == NULL
3454+
? "botright sbuf %d"
3455+
: (char *)term->tl_opencmd;
3456+
size_t len = strlen(cmd) + 50;
3457+
char *buf = alloc(len);
3458+
3459+
if (buf != NULL)
3460+
{
3461+
ch_log(NULL, "terminal job finished, opening window");
3462+
vim_snprintf(buf, len, cmd, fnum);
3463+
do_cmdline_cmd((char_u *)buf);
3464+
vim_free(buf);
3465+
}
34623466
}
34633467
else
34643468
ch_log(NULL, "terminal job finished");

src/testdir/test_terminal.vim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,12 @@ func Test_terminal_finish_open_close()
567567
call assert_fails("call term_start(cmd, {'term_opencmd': 'split %d and %s'})", 'E475:')
568568
call assert_fails("call term_start(cmd, {'term_opencmd': 'split % and %d'})", 'E475:')
569569

570-
call term_start(cmd, {'term_finish': 'open', 'term_opencmd': '4split | buffer %d'})
570+
call term_start(cmd, {'term_finish': 'open', 'term_opencmd': '4split | buffer %d | let g:result = "opened the buffer in a window"'})
571571
close!
572572
call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime)
573573
call assert_equal(4, winheight(0))
574+
call assert_equal('opened the buffer in a window', g:result)
575+
unlet g:result
574576
bwipe
575577
endfunc
576578

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
1979,
753755
/**/
754756
1978,
755757
/**/

0 commit comments

Comments
 (0)