mirror of
https://github.com/vim/vim.git
synced 2025-09-30 04:44:14 -04:00
patch 7.4.1465
Problem: Coverity reported possible use of NULL pointer when using buffer output with JSON mode. Solution: Make it actually possible to use JSON mode with a buffer. Re-encode the JSON to append it to the buffer.
This commit is contained in:
@@ -926,7 +926,8 @@ channel_set_options(channel_T *channel, jobopt_T *opt)
|
|||||||
|
|
||||||
if ((opt->jo_set & JO_OUT_IO) && opt->jo_io[PART_OUT] == JIO_BUFFER)
|
if ((opt->jo_set & JO_OUT_IO) && opt->jo_io[PART_OUT] == JIO_BUFFER)
|
||||||
{
|
{
|
||||||
/* writing output to a buffer. Force mode to NL. */
|
/* writing output to a buffer. Default mode is NL. */
|
||||||
|
if (!(opt->jo_set & JO_OUT_MODE))
|
||||||
channel->ch_part[PART_OUT].ch_mode = MODE_NL;
|
channel->ch_part[PART_OUT].ch_mode = MODE_NL;
|
||||||
channel->ch_part[PART_OUT].ch_buffer =
|
channel->ch_part[PART_OUT].ch_buffer =
|
||||||
find_buffer(opt->jo_io_name[PART_OUT]);
|
find_buffer(opt->jo_io_name[PART_OUT]);
|
||||||
@@ -1560,6 +1561,11 @@ may_invoke_callback(channel_T *channel, int part)
|
|||||||
u_sync(TRUE);
|
u_sync(TRUE);
|
||||||
u_save(lnum, lnum + 1);
|
u_save(lnum, lnum + 1);
|
||||||
|
|
||||||
|
if (msg == NULL)
|
||||||
|
/* JSON or JS mode: re-encode the message. */
|
||||||
|
msg = json_encode(listtv, ch_mode);
|
||||||
|
if (msg != NULL)
|
||||||
|
{
|
||||||
ml_append(lnum, msg, 0, FALSE);
|
ml_append(lnum, msg, 0, FALSE);
|
||||||
appended_lines_mark(lnum, 1L);
|
appended_lines_mark(lnum, 1L);
|
||||||
curbuf = save_curbuf;
|
curbuf = save_curbuf;
|
||||||
@@ -1588,6 +1594,7 @@ may_invoke_callback(channel_T *channel, int part)
|
|||||||
channel_need_redraw = TRUE;
|
channel_need_redraw = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (callback != NULL)
|
if (callback != NULL)
|
||||||
{
|
{
|
||||||
/* invoke the channel callback */
|
/* invoke the channel callback */
|
||||||
|
@@ -426,6 +426,32 @@ func Test_pipe_to_nameless_buffer()
|
|||||||
endtry
|
endtry
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_pipe_to_buffer_json()
|
||||||
|
if !has('job')
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
call ch_log('Test_pipe_to_buffer_json()')
|
||||||
|
let job = job_start(s:python . " test_channel_pipe.py",
|
||||||
|
\ {'out-io': 'buffer', 'out-mode': 'json'})
|
||||||
|
call assert_equal("run", job_status(job))
|
||||||
|
try
|
||||||
|
let handle = job_getchannel(job)
|
||||||
|
call ch_sendraw(handle, "echo [0, \"hello\"]\n")
|
||||||
|
call ch_sendraw(handle, "echo [-2, 12.34]\n")
|
||||||
|
exe ch_getbufnr(handle, "out") . 'sbuf'
|
||||||
|
for i in range(100)
|
||||||
|
sleep 10m
|
||||||
|
if line('$') >= 3
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
call assert_equal(['Reading from channel output...', '[0,"hello"]', '[-2,12.34]'], getline(1, '$'))
|
||||||
|
bwipe!
|
||||||
|
finally
|
||||||
|
call job_stop(job)
|
||||||
|
endtry
|
||||||
|
endfunc
|
||||||
|
|
||||||
""""""""""
|
""""""""""
|
||||||
|
|
||||||
let s:unletResponse = ''
|
let s:unletResponse = ''
|
||||||
|
@@ -743,6 +743,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1465,
|
||||||
/**/
|
/**/
|
||||||
1464,
|
1464,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user