@@ -739,10 +739,10 @@ channel_open(
739739 * After putting the socket in non-blocking mode, connect() will
740740 * return EINPROGRESS, select() will not wait (as if writing is
741741 * possible), need to use getsockopt() to check if the socket is
742- * actually connect.
743- * We detect an failure to connect when both read and write fds
742+ * actually able to connect.
743+ * We detect an failure to connect when either read and write fds
744744 * are set. Use getsockopt() to find out what kind of failure. */
745- if (FD_ISSET (sd , & rfds ) && FD_ISSET (sd , & wfds ))
745+ if (FD_ISSET (sd , & rfds ) || FD_ISSET (sd , & wfds ))
746746 {
747747 ret = getsockopt (sd ,
748748 SOL_SOCKET , SO_ERROR , & so_error , & so_error_len );
@@ -1535,6 +1535,9 @@ may_invoke_callback(channel_T *channel, int part)
15351535 * get everything we have. */
15361536 msg = channel_get_all (channel , part );
15371537
1538+ if (msg == NULL )
1539+ return FALSE; /* out of memory (and avoids Coverity warning) */
1540+
15381541 argv [1 ].v_type = VAR_STRING ;
15391542 argv [1 ].vval .v_string = msg ;
15401543 }
@@ -1570,21 +1573,22 @@ may_invoke_callback(channel_T *channel, int part)
15701573 {
15711574 if (buffer != NULL )
15721575 {
1573- buf_T * save_curbuf = curbuf ;
1574- linenr_T lnum = buffer -> b_ml .ml_line_count ;
1575-
1576- /* Append to the buffer */
1577- ch_logn (channel , "appending line %d to buffer" , (int )lnum + 1 );
1578-
1579- curbuf = buffer ;
1580- u_sync (TRUE);
1581- u_save (lnum , lnum + 1 );
1582-
15831576 if (msg == NULL )
15841577 /* JSON or JS mode: re-encode the message. */
15851578 msg = json_encode (listtv , ch_mode );
15861579 if (msg != NULL )
15871580 {
1581+ buf_T * save_curbuf = curbuf ;
1582+ linenr_T lnum = buffer -> b_ml .ml_line_count ;
1583+
1584+ /* Append to the buffer */
1585+ ch_logn (channel , "appending line %d to buffer" , (int )lnum + 1 );
1586+
1587+ curbuf = buffer ;
1588+ u_sync (TRUE);
1589+ /* ignore undo failure, undo is not very useful here */
1590+ ignored = u_save (lnum , lnum + 1 );
1591+
15881592 ml_append (lnum , msg , 0 , FALSE);
15891593 appended_lines_mark (lnum , 1L );
15901594 curbuf = save_curbuf ;
0 commit comments