Skip to content

Commit 9e40c4b

Browse files
committed
patch 8.2.2036: buffer messed up if creating the quickfix window fails
Problem: Current buffer is messed up if creating a new buffer for the quickfix window fails. Solution: Check that creating the buffer succeeds. (closes #7352)
1 parent f637bce commit 9e40c4b

4 files changed

Lines changed: 55 additions & 3 deletions

File tree

src/quickfix.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4151,13 +4151,15 @@ qf_open_new_cwindow(qf_info_T *qi, int height)
41514151
if (qf_buf != NULL)
41524152
{
41534153
// Use the existing quickfix buffer
4154-
(void)do_ecmd(qf_buf->b_fnum, NULL, NULL, NULL, ECMD_ONE,
4155-
ECMD_HIDE + ECMD_OLDBUF, oldwin);
4154+
if (do_ecmd(qf_buf->b_fnum, NULL, NULL, NULL, ECMD_ONE,
4155+
ECMD_HIDE + ECMD_OLDBUF, oldwin) == FAIL)
4156+
return FAIL;
41564157
}
41574158
else
41584159
{
41594160
// Create a new quickfix buffer
4160-
(void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, oldwin);
4161+
if (do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, oldwin) == FAIL)
4162+
return FAIL;
41614163

41624164
// save the number of the new buffer
41634165
qi->qf_bufnr = curbuf->b_fnum;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
|a+0&#ffffff0|n|y|t|h|i|n|g| @66
2+
> @74
3+
|t|r|y| @71
4+
|X+3&&|q|u|i|c|k|f|i|x|F|a|i|l|s| |[|+|]| @38|2|,|0|-|1| @9|T|o|p
5+
| +0&&@74
6+
|t|r|y| @71
7+
@2|a|n|y|t|h|i|n|g| @64
8+
|X+1&&|q|u|i|c|k|f|i|x|F|a|i|l|s| |[|+|]| @38|2|,|0|-|1| @9|5|0|%
9+
| +0&&@74
10+
|~+0#4040ff13&| @73
11+
|~| @73
12+
|[+1#0000000&|N|o| |N|a|m|e|]| @47|0|,|0|-|1| @9|A|l@1
13+
| +0&&@74

src/testdir/test_quickfix.vim

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5218,4 +5218,39 @@ func Test_add_invalid_entry_with_qf_window()
52185218
cclose
52195219
endfunc
52205220

5221+
" Test for very weird problem: autocommand causes a failure, resulting opening
5222+
" the quickfix window to fail. This still splits the window, but otherwise
5223+
" should not mess up buffers.
5224+
func Test_quickfix_window_fails_to_open()
5225+
CheckScreendump
5226+
5227+
let lines =<< trim END
5228+
anything
5229+
try
5230+
anything
5231+
endtry
5232+
END
5233+
call writefile(lines, 'XquickfixFails')
5234+
5235+
let lines =<< trim END
5236+
split XquickfixFails
5237+
silent vimgrep anything %
5238+
normal o
5239+
au BufLeave * ++once source XquickfixFails
5240+
" This will trigger the autocommand, which causes an error, what follows
5241+
" is aborted but the window was already split.
5242+
silent! cwindow
5243+
END
5244+
call writefile(lines, 'XtestWinFails')
5245+
let buf = RunVimInTerminal('-S XtestWinFails', #{rows: 13})
5246+
call VerifyScreenDump(buf, 'Test_quickfix_window_fails', {})
5247+
5248+
" clean up
5249+
call term_sendkeys(buf, ":bwipe!\<CR>")
5250+
call term_wait(buf)
5251+
call StopVimInTerminal(buf)
5252+
call delete('XtestWinFails')
5253+
call delete('XquickfixFails')
5254+
endfunc
5255+
52215256
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2036,
753755
/**/
754756
2035,
755757
/**/

0 commit comments

Comments
 (0)