diff options
author | Bram Moolenaar <Bram@vim.org> | 2016-10-03 21:37:41 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2016-10-03 21:37:41 +0200 |
commit | ec68a99464055029c01082762517e97245ddae0c (patch) | |
tree | 36558e0f7c6a0bb29bb62f19aa3b0d73371e6305 /src/channel.c | |
parent | 84dbd494dca599ecff05b2c2279d402c12e6d197 (diff) | |
download | vim-ec68a99464055029c01082762517e97245ddae0c.zip |
patch 8.0.0022
Problem: If a channel in NL mode is missing the NL at the end the remaining
characters are dropped.
Solution: When the channel is closed use the remaining text. (Ozaki Kiichi)
Diffstat (limited to 'src/channel.c')
-rw-r--r-- | src/channel.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/channel.c b/src/channel.c index 13fb65302..d4ec60b75 100644 --- a/src/channel.c +++ b/src/channel.c @@ -2355,8 +2355,9 @@ may_invoke_callback(channel_T *channel, int part) typval_T *listtv = NULL; typval_T argv[CH_JSON_MAX_ARGS]; int seq_nr = -1; - ch_mode_T ch_mode = channel->ch_part[part].ch_mode; - cbq_T *cbhead = &channel->ch_part[part].ch_cb_head; + chanpart_T *ch_part = &channel->ch_part[part]; + ch_mode_T ch_mode = ch_part->ch_mode; + cbq_T *cbhead = &ch_part->ch_cb_head; cbq_T *cbitem; char_u *callback = NULL; partial_T *partial = NULL; @@ -2376,10 +2377,10 @@ may_invoke_callback(channel_T *channel, int part) callback = cbitem->cq_callback; partial = cbitem->cq_partial; } - else if (channel->ch_part[part].ch_callback != NULL) + else if (ch_part->ch_callback != NULL) { - callback = channel->ch_part[part].ch_callback; - partial = channel->ch_part[part].ch_partial; + callback = ch_part->ch_callback; + partial = ch_part->ch_partial; } else { @@ -2387,11 +2388,11 @@ may_invoke_callback(channel_T *channel, int part) partial = channel->ch_partial; } - buffer = channel->ch_part[part].ch_bufref.br_buf; - if (buffer != NULL && !bufref_valid(&channel->ch_part[part].ch_bufref)) + buffer = ch_part->ch_bufref.br_buf; + if (buffer != NULL && !bufref_valid(&ch_part->ch_bufref)) { /* buffer was wiped out */ - channel->ch_part[part].ch_bufref.br_buf = NULL; + ch_part->ch_bufref.br_buf = NULL; buffer = NULL; } @@ -2452,7 +2453,7 @@ may_invoke_callback(channel_T *channel, int part) if (ch_mode == MODE_NL) { - char_u *nl; + char_u *nl = NULL; char_u *buf; readq_T *node; @@ -2465,10 +2466,25 @@ may_invoke_callback(channel_T *channel, int part) if (nl != NULL) break; if (channel_collapse(channel, part, TRUE) == FAIL) + { + if (ch_part->ch_fd == INVALID_FD && node->rq_buflen > 0) + break; return FALSE; /* incomplete message */ + } } buf = node->rq_buffer; + if (nl == NULL) + { + /* Flush remaining message that is missing a NL. */ + buf = vim_realloc(buf, node->rq_buflen + 1); + if (buf == NULL) + return FALSE; + node->rq_buffer = buf; + nl = buf + node->rq_buflen++; + *nl = NUL; + } + /* Convert NUL to NL, the internal representation. */ for (p = buf; p < nl && p < buf + node->rq_buflen; ++p) if (*p == NUL) |