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. Files: src/channel.c, src/testdir/test_channel.vim
*** ../vim-7.4.1464/src/channel.c 2016-02-28 22:33:43.028904937 +0100 --- src/channel.c 2016-02-29 22:46:15.531699091 +0100 *************** *** 926,933 **** if ((opt->jo_set & JO_OUT_IO) && opt->jo_io[PART_OUT] == JIO_BUFFER) { ! /* writing output to a buffer. Force mode to NL. */ ! channel->ch_part[PART_OUT].ch_mode = MODE_NL; channel->ch_part[PART_OUT].ch_buffer = find_buffer(opt->jo_io_name[PART_OUT]); ch_logs(channel, "writing to buffer '%s'", --- 926,934 ---- if ((opt->jo_set & JO_OUT_IO) && opt->jo_io[PART_OUT] == JIO_BUFFER) { ! /* 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_buffer = find_buffer(opt->jo_io_name[PART_OUT]); ch_logs(channel, "writing to buffer '%s'", *************** *** 1560,1591 **** u_sync(TRUE); u_save(lnum, lnum + 1); ! ml_append(lnum, msg, 0, FALSE); ! appended_lines_mark(lnum, 1L); ! curbuf = save_curbuf; ! ! if (buffer->b_nwindows > 0) { ! win_T *wp; ! win_T *save_curwin; ! FOR_ALL_WINDOWS(wp) { ! if (wp->w_buffer == buffer ! && wp->w_cursor.lnum == lnum ! && wp->w_cursor.col == 0) { ! ++wp->w_cursor.lnum; ! save_curwin = curwin; ! curwin = wp; ! curbuf = curwin->w_buffer; ! scroll_cursor_bot(0, FALSE); ! curwin = save_curwin; ! curbuf = curwin->w_buffer; } } - redraw_buf_later(buffer, VALID); - channel_need_redraw = TRUE; } } if (callback != NULL) --- 1561,1598 ---- u_sync(TRUE); 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); ! appended_lines_mark(lnum, 1L); ! curbuf = save_curbuf; ! if (buffer->b_nwindows > 0) { ! win_T *wp; ! win_T *save_curwin; ! ! FOR_ALL_WINDOWS(wp) { ! if (wp->w_buffer == buffer ! && wp->w_cursor.lnum == lnum ! && wp->w_cursor.col == 0) ! { ! ++wp->w_cursor.lnum; ! save_curwin = curwin; ! curwin = wp; ! curbuf = curwin->w_buffer; ! scroll_cursor_bot(0, FALSE); ! curwin = save_curwin; ! curbuf = curwin->w_buffer; ! } } + redraw_buf_later(buffer, VALID); + channel_need_redraw = TRUE; } } } if (callback != NULL) *** ../vim-7.4.1464/src/testdir/test_channel.vim 2016-02-28 19:50:47.555824204 +0100 --- src/testdir/test_channel.vim 2016-02-29 22:51:50.816154878 +0100 *************** *** 426,431 **** --- 426,457 ---- endtry 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 = '' *** ../vim-7.4.1464/src/version.c 2016-02-29 22:05:16.841676901 +0100 --- src/version.c 2016-02-29 22:47:35.726851366 +0100 *************** *** 745,746 **** --- 745,748 ---- { /* Add new patch number below this line */ + /**/ + 1465, /**/ -- ARTHUR: The swallow may fly south with the sun, or the house martin or the plover seek warmer hot lands in winter, yet these are not strangers to our land. SOLDIER: Are you suggesting coconuts migrate? "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org /// -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.