Skip to content

Commit 5cefd40

Browse files
committed
patch 7.4.1329
Problem: Crash when using channel that failed to open. Solution: Check for NULL. Update messages. (Yukihiro Nakadaira)
1 parent 12dcf02 commit 5cefd40

4 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/channel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ channel_open(char *hostname, int port_in, int waittime, void (*close_cb)(void))
634634
{
635635
/* Get here when the server can't be found. */
636636
ch_error(NULL, "Cannot connect to port after retry\n");
637-
PERROR(_("E899: Cannot connect to port after retry2"));
637+
PERROR(_("E899: Cannot connect to port after retry"));
638638
sock_close(sd);
639639
channel_free(channel);
640640
return NULL;
@@ -1220,7 +1220,7 @@ channel_status(channel_T *channel)
12201220
void
12211221
channel_close(channel_T *channel)
12221222
{
1223-
ch_log(channel, "Closing channel");
1223+
ch_log(channel, "Closing channel\n");
12241224

12251225
#ifdef FEAT_GUI
12261226
channel_gui_unregister(channel);

src/eval.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21828,7 +21828,10 @@ get_tv_string_buf_chk(typval_T *varp, char_u *buf)
2182821828
channel_T *channel = varp->vval.v_channel;
2182921829
char *status = channel_status(channel);
2183021830

21831-
vim_snprintf((char *)buf, NUMBUFLEN,
21831+
if (channel == NULL)
21832+
vim_snprintf((char *)buf, NUMBUFLEN, "channel %s", status);
21833+
else
21834+
vim_snprintf((char *)buf, NUMBUFLEN,
2183221835
"channel %d %s", channel->ch_id, status);
2183321836
return buf;
2183421837
}
@@ -22467,7 +22470,8 @@ copy_tv(typval_T *from, typval_T *to)
2246722470
case VAR_CHANNEL:
2246822471
#ifdef FEAT_CHANNEL
2246922472
to->vval.v_channel = from->vval.v_channel;
22470-
++to->vval.v_channel->ch_refcount;
22473+
if (to->vval.v_channel != NULL)
22474+
++to->vval.v_channel->ch_refcount;
2247122475
break;
2247222476
#endif
2247322477
case VAR_STRING:

src/testdir/test_channel.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,9 @@ endfunc
318318
func Test_unlet_handle()
319319
call s:run_server('s:unlet_handle')
320320
endfunc
321+
322+
func Test_open_fail()
323+
silent! let ch = ch_open("noserver")
324+
echo ch
325+
let d = ch
326+
endfunc

src/version.c

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

748748
static int included_patches[] =
749749
{ /* Add new patch number below this line */
750+
/**/
751+
1329,
750752
/**/
751753
1328,
752754
/**/

0 commit comments

Comments
 (0)