summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-11-23 20:15:08 +0100
committerBram Moolenaar <Bram@vim.org>2020-11-23 20:15:08 +0100
commit9e40c4b15ebfbc84947a3f34b1bd53e397b57f51 (patch)
treed40f331175818b69219e5327e3f297707dc76d4f
parentf637bceb6135139dc1891a15de8fa134c2ca2d97 (diff)
downloadvim-git-9e40c4b15ebfbc84947a3f34b1bd53e397b57f51.tar.gz
patch 8.2.2036: buffer messed up if creating the quickfix window failsv8.2.2036
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)
-rw-r--r--src/quickfix.c8
-rw-r--r--src/testdir/dumps/Test_quickfix_window_fails.dump13
-rw-r--r--src/testdir/test_quickfix.vim35
-rw-r--r--src/version.c2
4 files changed, 55 insertions, 3 deletions
diff --git a/src/quickfix.c b/src/quickfix.c
index 40897b6b6..5e46ad2e9 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -4151,13 +4151,15 @@ qf_open_new_cwindow(qf_info_T *qi, int height)
if (qf_buf != NULL)
{
// Use the existing quickfix buffer
- (void)do_ecmd(qf_buf->b_fnum, NULL, NULL, NULL, ECMD_ONE,
- ECMD_HIDE + ECMD_OLDBUF, oldwin);
+ if (do_ecmd(qf_buf->b_fnum, NULL, NULL, NULL, ECMD_ONE,
+ ECMD_HIDE + ECMD_OLDBUF, oldwin) == FAIL)
+ return FAIL;
}
else
{
// Create a new quickfix buffer
- (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, oldwin);
+ if (do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, oldwin) == FAIL)
+ return FAIL;
// save the number of the new buffer
qi->qf_bufnr = curbuf->b_fnum;
diff --git a/src/testdir/dumps/Test_quickfix_window_fails.dump b/src/testdir/dumps/Test_quickfix_window_fails.dump
new file mode 100644
index 000000000..769e30a2d
--- /dev/null
+++ b/src/testdir/dumps/Test_quickfix_window_fails.dump
@@ -0,0 +1,13 @@
+|a+0&#ffffff0|n|y|t|h|i|n|g| @66
+> @74
+|t|r|y| @71
+|X+3&&|q|u|i|c|k|f|i|x|F|a|i|l|s| |[|+|]| @38|2|,|0|-|1| @9|T|o|p
+| +0&&@74
+|t|r|y| @71
+@2|a|n|y|t|h|i|n|g| @64
+|X+1&&|q|u|i|c|k|f|i|x|F|a|i|l|s| |[|+|]| @38|2|,|0|-|1| @9|5|0|%
+| +0&&@74
+|~+0#4040ff13&| @73
+|~| @73
+|[+1#0000000&|N|o| |N|a|m|e|]| @47|0|,|0|-|1| @9|A|l@1
+| +0&&@74
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index cbdc610bb..759cb0d74 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -5218,4 +5218,39 @@ func Test_add_invalid_entry_with_qf_window()
cclose
endfunc
+" Test for very weird problem: autocommand causes a failure, resulting opening
+" the quickfix window to fail. This still splits the window, but otherwise
+" should not mess up buffers.
+func Test_quickfix_window_fails_to_open()
+ CheckScreendump
+
+ let lines =<< trim END
+ anything
+ try
+ anything
+ endtry
+ END
+ call writefile(lines, 'XquickfixFails')
+
+ let lines =<< trim END
+ split XquickfixFails
+ silent vimgrep anything %
+ normal o
+ au BufLeave * ++once source XquickfixFails
+ " This will trigger the autocommand, which causes an error, what follows
+ " is aborted but the window was already split.
+ silent! cwindow
+ END
+ call writefile(lines, 'XtestWinFails')
+ let buf = RunVimInTerminal('-S XtestWinFails', #{rows: 13})
+ call VerifyScreenDump(buf, 'Test_quickfix_window_fails', {})
+
+ " clean up
+ call term_sendkeys(buf, ":bwipe!\<CR>")
+ call term_wait(buf)
+ call StopVimInTerminal(buf)
+ call delete('XtestWinFails')
+ call delete('XquickfixFails')
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index ca8164309..3f79d3a85 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2036,
+/**/
2035,
/**/
2034,