diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/quickfix.c | 24 | ||||
-rw-r--r-- | src/nvim/testdir/test_quickfix.vim | 27 |
2 files changed, 41 insertions, 10 deletions
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 484168e798..ddce1e922d 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -3757,13 +3757,13 @@ static int qf_buf_add_line(buf_T *buf, linenr_T lnum, const qfline_T *qfp, buf_T *errbuf; if (qfp->qf_module != NULL) { - STRCPY(IObuff, qfp->qf_module); + STRLCPY(IObuff, qfp->qf_module, IOSIZE - 1); len = (int)STRLEN(IObuff); } else if (qfp->qf_fnum != 0 && (errbuf = buflist_findnr(qfp->qf_fnum)) != NULL && errbuf->b_fname != NULL) { if (qfp->qf_type == 1) { // :helpgrep - STRLCPY(IObuff, path_tail(errbuf->b_fname), sizeof(IObuff)); + STRLCPY(IObuff, path_tail(errbuf->b_fname), IOSIZE - 1); } else { // shorten the file name if not done already if (errbuf->b_sfname == NULL @@ -3773,33 +3773,37 @@ static int qf_buf_add_line(buf_T *buf, linenr_T lnum, const qfline_T *qfp, } shorten_buf_fname(errbuf, dirname, false); } - STRLCPY(IObuff, errbuf->b_fname, sizeof(IObuff)); + STRLCPY(IObuff, errbuf->b_fname, IOSIZE - 1); } len = (int)STRLEN(IObuff); } else { len = 0; } - IObuff[len++] = '|'; - + if (len < IOSIZE - 1) { + IObuff[len++] = '|'; + } if (qfp->qf_lnum > 0) { - snprintf((char *)IObuff + len, sizeof(IObuff), "%" PRId64, + snprintf((char *)IObuff + len, (size_t)(IOSIZE - len), "%" PRId64, (int64_t)qfp->qf_lnum); len += (int)STRLEN(IObuff + len); if (qfp->qf_col > 0) { - snprintf((char *)IObuff + len, sizeof(IObuff), " col %d", qfp->qf_col); + snprintf((char *)IObuff + len, (size_t)(IOSIZE - len), " col %d", + qfp->qf_col); len += (int)STRLEN(IObuff + len); } - snprintf((char *)IObuff + len, sizeof(IObuff), "%s", + snprintf((char *)IObuff + len, (size_t)(IOSIZE - len), "%s", (char *)qf_types(qfp->qf_type, qfp->qf_nr)); len += (int)STRLEN(IObuff + len); } else if (qfp->qf_pattern != NULL) { qf_fmt_text(qfp->qf_pattern, IObuff + len, IOSIZE - len); len += (int)STRLEN(IObuff + len); } - IObuff[len++] = '|'; - IObuff[len++] = ' '; + if (len < IOSIZE - 2) { + IObuff[len++] = '|'; + IObuff[len++] = ' '; + } // Remove newlines and leading whitespace from the text. // For an unrecognized line keep the indent, the compiler may diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 35555ca9d3..926103b69f 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -554,6 +554,33 @@ func s:test_xhelpgrep(cchar) " This wipes out the buffer, make sure that doesn't cause trouble. Xclose + " When the current window is vertically split, jumping to a help match + " should open the help window at the top. + only | enew + let w1 = win_getid() + vert new + let w2 = win_getid() + Xnext + let w3 = win_getid() + call assert_true(&buftype == 'help') + call assert_true(winnr() == 1) + " See jump_to_help_window() for details + let w2_width = winwidth(w2) + if w2_width != &columns && w2_width < 80 + call assert_equal(['col', [['leaf', w3], + \ ['row', [['leaf', w2], ['leaf', w1]]]]], winlayout()) + else + call assert_equal(['row', [['col', [['leaf', w3], ['leaf', w2]]], + \ ['leaf', w1]]] , winlayout()) + endif + + new | only + set buftype=help + set modified + call assert_fails('Xnext', 'E37:') + set nomodified + new | only + if a:cchar == 'l' " When a help window is present, running :lhelpgrep should reuse the " help window and not the current window |