Mercurial > vim
comparison src/channel.c @ 8346:8fa75a4c39bd v7.4.1465
commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Feb 29 22:55:56 2016 +0100
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.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 29 Feb 2016 23:00:04 +0100 |
parents | ad4b00bf2984 |
children | a0cff08e7aa3 |
comparison
equal
deleted
inserted
replaced
8345:efc1e88341c6 | 8346:8fa75a4c39bd |
---|---|
924 *cbp = NULL; | 924 *cbp = NULL; |
925 } | 925 } |
926 | 926 |
927 if ((opt->jo_set & JO_OUT_IO) && opt->jo_io[PART_OUT] == JIO_BUFFER) | 927 if ((opt->jo_set & JO_OUT_IO) && opt->jo_io[PART_OUT] == JIO_BUFFER) |
928 { | 928 { |
929 /* writing output to a buffer. Force mode to NL. */ | 929 /* writing output to a buffer. Default mode is NL. */ |
930 channel->ch_part[PART_OUT].ch_mode = MODE_NL; | 930 if (!(opt->jo_set & JO_OUT_MODE)) |
931 channel->ch_part[PART_OUT].ch_mode = MODE_NL; | |
931 channel->ch_part[PART_OUT].ch_buffer = | 932 channel->ch_part[PART_OUT].ch_buffer = |
932 find_buffer(opt->jo_io_name[PART_OUT]); | 933 find_buffer(opt->jo_io_name[PART_OUT]); |
933 ch_logs(channel, "writing to buffer '%s'", | 934 ch_logs(channel, "writing to buffer '%s'", |
934 (char *)channel->ch_part[PART_OUT].ch_buffer->b_ffname); | 935 (char *)channel->ch_part[PART_OUT].ch_buffer->b_ffname); |
935 } | 936 } |
1558 | 1559 |
1559 curbuf = buffer; | 1560 curbuf = buffer; |
1560 u_sync(TRUE); | 1561 u_sync(TRUE); |
1561 u_save(lnum, lnum + 1); | 1562 u_save(lnum, lnum + 1); |
1562 | 1563 |
1563 ml_append(lnum, msg, 0, FALSE); | 1564 if (msg == NULL) |
1564 appended_lines_mark(lnum, 1L); | 1565 /* JSON or JS mode: re-encode the message. */ |
1565 curbuf = save_curbuf; | 1566 msg = json_encode(listtv, ch_mode); |
1566 | 1567 if (msg != NULL) |
1567 if (buffer->b_nwindows > 0) | |
1568 { | 1568 { |
1569 win_T *wp; | 1569 ml_append(lnum, msg, 0, FALSE); |
1570 win_T *save_curwin; | 1570 appended_lines_mark(lnum, 1L); |
1571 | 1571 curbuf = save_curbuf; |
1572 FOR_ALL_WINDOWS(wp) | 1572 |
1573 if (buffer->b_nwindows > 0) | |
1573 { | 1574 { |
1574 if (wp->w_buffer == buffer | 1575 win_T *wp; |
1575 && wp->w_cursor.lnum == lnum | 1576 win_T *save_curwin; |
1576 && wp->w_cursor.col == 0) | 1577 |
1578 FOR_ALL_WINDOWS(wp) | |
1577 { | 1579 { |
1578 ++wp->w_cursor.lnum; | 1580 if (wp->w_buffer == buffer |
1579 save_curwin = curwin; | 1581 && wp->w_cursor.lnum == lnum |
1580 curwin = wp; | 1582 && wp->w_cursor.col == 0) |
1581 curbuf = curwin->w_buffer; | 1583 { |
1582 scroll_cursor_bot(0, FALSE); | 1584 ++wp->w_cursor.lnum; |
1583 curwin = save_curwin; | 1585 save_curwin = curwin; |
1584 curbuf = curwin->w_buffer; | 1586 curwin = wp; |
1587 curbuf = curwin->w_buffer; | |
1588 scroll_cursor_bot(0, FALSE); | |
1589 curwin = save_curwin; | |
1590 curbuf = curwin->w_buffer; | |
1591 } | |
1585 } | 1592 } |
1593 redraw_buf_later(buffer, VALID); | |
1594 channel_need_redraw = TRUE; | |
1586 } | 1595 } |
1587 redraw_buf_later(buffer, VALID); | |
1588 channel_need_redraw = TRUE; | |
1589 } | 1596 } |
1590 } | 1597 } |
1591 if (callback != NULL) | 1598 if (callback != NULL) |
1592 { | 1599 { |
1593 /* invoke the channel callback */ | 1600 /* invoke the channel callback */ |